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

RE: Accessing node-sets by index with position()

Subject: RE: Accessing node-sets by index with position()
From: Americo Albuquerque <melinor@xxxxxxxx>
Date: Tue, 23 Sep 2003 23:46:49 +0100
xsl node index

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Ryan Sawatzky
> Sent: Tuesday, September 23, 2003 8:13 PM
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Accessing node-sets by index with position()
> 
> 
(...)
> 
> 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 is a strange way of doing this but...

The position() is always refered to the current node set, in this case
$set inside the value-of, so this is the same as get $set that has a
position() :) this is always true. You get 111 because the value-of
always get the first node of a nodeset

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

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

Hope this helps

Regards,
Americo Albuquerque


 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.