View Single Post
  #2 (permalink)  
Old January 4th, 2008, 06:47 AM
mhkay's Avatar
mhkay mhkay is offline
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The question applies to iteration over any sequence, except for the special case where the items in the sequence are siblings, in which case you can use preceding-sibling and following-sibling.

In general, use

<xsl:variable name="sequence" select="current-group()">
<xsl:for-each select="1 to count($sequence)">
  <xsl:variable name="position" select="."/>
  <xsl:variable name="currentItem" select="$sequence[$position]"/>
  <xsl:variable name="previousItem" select="$sequence[$position - 1]"/>

Just remember that inside the for-each, the context item (.) is a number, not a node.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote