From: NIENKE, Bill P. - ACCOR-NA [mailto:Nienke_Bill(_at_)accor-na(_dot_)com]
Sent: Thursday, December 12, 2002 2:36 PM
Subject: [xsl] accessing individual nodes while iterating
Hi,
I'm having troubles translating XML into HTML. I can iterate
through the WPT
nodes, but I get all of the child nodes too. Since I don't
want all of the
nodes in my output I'd like to format like this:
<a
href="http://www.geocaching.com/seek/cache_details.aspx?ID=38989">Hunt
for the Hideout by Nick & Nora</a> - GC984D
You didn't provide your current XSLT code, but I'm guessing that you're
using xsl:copy-of instead of xsl:value-of. copy-of will do a deep copy of
the node (attributes and child nodes included). value-of copies the string
value of the select expression. The following does what you want:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:for-each select="wpt">
<a>
<xsl:attribute name="href"><xsl:value-of
select="url"/></xsl:attribute>
<xsl:value-of select="desc"/>
</a> - <xsl:value-of select="name"/><br/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Also, how would I work an xsl:sort into the iteration?
xsl:sort must appear before the template body in a for-each iteration:
<xsl:for-each select="wpt">
<xsl:sort select="desc"/>
etc.
</xsl:for-each>
hth,
b.
| brian martinez
brian(_dot_)martinez(_at_)trip(_dot_)com |
| senior gui programmer 303.708.7248 |
| trip network, inc. fax 303.790.9350 |
| 6436 s. racine cir. englewood, co 80111 |
| http://www.cheaptickets.com/ http://www.trip.com/ |
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list