[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Accessing node-sets by index with position()

Subject: Accessing node-sets by index with position()
From: Ryan Sawatzky <rsawatzky@xxxxxxxxxxx>
Date: Tue, 23 Sep 2003 14:13:16 -0500
xsl node index
Hi everyone,

I am trying to iterate through a list of nodes in a node-set by index using the position() function, and I am running into some difficulties.

XML snippet -----

<info>
   <field>111</field>
   <field>222</field>
</info>

XSLT snippet -----
<!-- $set is the node-set containing the two <field> elements -->

<xsl:for-each select="$set">
   <xsl:text>Iteration #</xsl:text>
   <xsl:value-of select="position()"/>
   <xsl:text> is '</xsl:text>
   <xsl:value-of select="$set[position()]"/>
   <xsl:text>'&#10;</xsl:text>
</xsl:for-each>

This gives the following output
Iteration #1 is 111
Iteration #2 is 111

It seems as though the position() function is working, but when I try to get at the 2nd node by index, it goes to the first node. If I replace $set[position()] with $set[2], I get the following...

Iteration #1 is 222
Iteration #2 is 222

So I know that I the second node in the node set is correct, but position() won't get me to it. Does anyone know how I can fix this problem? Any help is greatly appreciated.

Thanks,
--Ryan



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.