Re: How to Display XML tags and values in an HTML page?
- From: Peter Flynn <peter.nosp@xxxxxxxxxxxxx>
- Date: Sun, 27 Nov 2005 22:17:39 +0000
drawbridgej@xxxxxxxxxxxx wrote:
> I've done a little xml and xsl, but am a relative newbie.
> I have been unable to find a style*** 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 <xsl:output 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/
.
- Follow-Ups:
- Re: How to Display XML tags and values in an HTML page?
- From: drawbridgej
- Re: How to Display XML tags and values in an HTML page?
- References:
- How to Display XML tags and values in an HTML page?
- From: drawbridgej
- How to Display XML tags and values in an HTML page?
- Prev by Date: How to Display XML tags and values in an HTML page?
- Next by Date: xpath query
- Previous by thread: How to Display XML tags and values in an HTML page?
- Next by thread: Re: How to Display XML tags and values in an HTML page?
- Index(es):