Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > How to Display XML tags and values in an HTML page?

Reply
Thread Tools

How to Display XML tags and values in an HTML page?

 
 
drawbridgej@sympatico.ca
Guest
Posts: n/a
 
      11-27-2005
I've done a little xml and xsl, but am a relative newbie.
I have been unable to find a stylesheet to process an xml file and
output the tagNames and tagValues in HTML. I have also posted this
message in tek-tips.

I can get the node names with name() and the value with xsl:value-of
.... but I would like to get the lowest level tagNames via the xsl. I'd
like to be able to build html for a number of different xml files.


I'm trying to get something like:

Flights
Flight 1
Flight_Number: BA123
Origin : GLA
Destination : LHR
Carrier : British Airways
Date : 01/01/2002
.....
other flights

from xml as follows:
<Flights>
<Flight>
<Flight_Number>BA123</Flight_Number>
<Origin>GLA</Origin>
<Destination>LHR</Destination>
<Carrier>British Airways</Carrier>
<Date>01/01/2002</Date>
</Flight>
<Flight>
<Flight_Number>BA4234</Flight_Number>
<Origin>GLA</Origin>
<Destination>YOW</Destination>
<Carrier>British Airways</Carrier>
<Date>01/01/2002</Date>
</Flight>
</Flights>


I've tried name() and local-name() but they return the name of the
parent node, not the leaf element name.
TIA

jack

 
Reply With Quote
 
 
 
 
Peter Flynn
Guest
Posts: n/a
 
      11-27-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> I've done a little xml and xsl, but am a relative newbie.
> I have been unable to find a stylesheet to process an xml file and
> output the tagNames and tagValues in HTML. I have also posted this
> message in tek-tips.


First of all, please read http://xml.silmaril.ie/authors/makeup/

> I can get the node names with name() and the value with xsl:value-of
> ... but I would like to get the lowest level tagNames via the xsl. I'd
> like to be able to build html for a number of different xml files.


Have you set <xslutput method="html"/> ?

>
> I'm trying to get something like:
>
> Flights
> Flight 1
> Flight_Number: BA123
> Origin : GLA
> Destination : LHR
> Carrier : British Airways
> Date : 01/01/2002
> .....
> other flights
>
> from xml as follows:
> <Flights>
> <Flight>
> <Flight_Number>BA123</Flight_Number>
> <Origin>GLA</Origin>
> <Destination>LHR</Destination>
> <Carrier>British Airways</Carrier>
> <Date>01/01/2002</Date>
> </Flight>
> <Flight>
> <Flight_Number>BA4234</Flight_Number>
> <Origin>GLA</Origin>
> <Destination>YOW</Destination>
> <Carrier>British Airways</Carrier>
> <Date>01/01/2002</Date>
> </Flight>
> </Flights>
>
>
> I've tried name() and local-name() but they return the name of the
> parent node, not the leaf element name.


As you didn't post your XSL code we can only guess at what you're doing.

What you need is a template for each element of your XML document,
giving the HTML element type that you want to be output for it, eg

<xsl:template match="Flights">
<h1>
<xsl:apply-templates/>
</h1>
</xsl:template>

<xsl:template match="Flight">
<h2>
<xsl:text>Flight </xsl:text>
<xsl:number/>
</h2>
<table>
<xsl:for-each select="*">
<tr>
<td>
<xsl:value-of select="name()"/>
</td>
<td>:</td>
<td>
<xsl:value-of select="."/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>

The XSL List is a good place to discuss the details of XSL[T]:
see the details of other FAQs at the address below.

///Peter
--
XML FAQ: http://xml.silmaril.ie/

 
Reply With Quote
 
 
 
 
drawbridgej@sympatico.ca
Guest
Posts: n/a
 
      11-28-2005
Thanks Peter,

I have partially solved the issue. Here is the output and the xsl Used.

Output:

List of matching Flights

Flight
Flight_Number: BA123
Origin: GLA
Destination: LHR
Carrier: British Airways
Date: 01/01/2002

Flight
Flight_Number: BA4234
Origin: GLA
Destination: YOW
Carrier: British Airways
Date: 01/01/2002

Flight
Flight_Number: AA4959
Origin: GLA
Destination: LHR
Carrier: American Airways
Date: 01/01/2002

Flight
Flight_Number: AC23
Origin: CAN
Destination: LHR
Carrier: Air Canada
Date: 01/02/2004


xsl:

<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="html" indent="no"/>
<xsl:template match="Flights">
<html>
<head>
<title>Matching Request Flights</title>
</head>
<body>
<h1>List of matching Flights </h1>
<xsl:apply-templates select="Flight"/>
</body>
</html>
</xsl:template>

<!-- Templates -->
<xsl:template match="Flight">
<!-- Display Flight-->
<tr><th><br/>
<b><font color="blue"><xsl:value-of select="local-name()"/></font></b>
</th></tr>
<table border="0">
<xsl:apply-templates />
</table>
</xsl:template>

<xsl:template match="Flight/*">
<tr><td><b><xsl:value-of select="local-name()"/>:</b></td>
<td><xsl:value-of select="."/></td></tr>
</xsl:template>

</xsl:stylesheet>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP Custom Tags as attribute values for other custom tags Dave Java 0 08-14-2006 02:21 PM
All style tags after the first 30 style tags on an HTML page are not applied in Internet Explorer Rob Nicholson ASP .Net 3 05-28-2005 03:11 PM
html tags within meta tags allowed? Donald Firesmith XML 5 01-08-2005 11:29 PM
CHtmlView: How to read html text before display, change and give to display changed html code? Marek Kurowski C Programming 1 08-18-2004 06:41 PM
RegEx to find CFML tags nested in HTML tags Dean H. Saxe Perl 0 01-03-2004 06:11 PM



Advertisments