p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   Accessing previous item in current-group() in loop (http://p2p.wrox.com/showthread.php?t=65001)

mikeymikey January 3rd, 2008 11:35 PM

Accessing previous item in current-group() in loop
Is there a way to check the previous item in current group?


<xsl:for-each select="current-group()">
  <xsl:if test="position() != 1">



Like are there any functions that can help me achieve the item in the comment?


mhkay January 4th, 2008 06:47 AM

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
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference

All times are GMT -4. The time now is 10:37 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.