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

RE: counter in nested for-eachs

Subject: RE: counter in nested for-eachs
From: David Neary <David@xxxxxxxxx>
Date: Thu, 15 May 2003 16:25:06 +0200
xsl for each counter

This is a FAQ? the answer is that there is no way to modify a variable.
However...

> i have two or three nested for-each elements, is it possible to
> have a global counter for all of them?
> 
> i would like that with every loop in every for-each a number
> is incremented by one..

... you can do it like this.

<xsl:for-each select="stuff">
  <xsl:variable name="stuffcount" select="count()"/>
  <xsl:variable name="stuffpos" select="position() - 1"/>
   <xsl:for-each select="more">
    <xsl:variable name="morecount" select="count()"/>
    <xsl:variable name="morepos" select="position() - 1 + $stuffpos *
$stuffcount"/>
     <xsl:for-each select="again">
      <xsl:variable name="againpos" select="position() - 1 + $morepos *
$morecount"/>
      <xsl:text>Current position: </xsl:text>
      <xsl:value-of select="$againpos" />
    </xsl:for-each>
  </xsl:for-each>
</xsl:for-each>

... but this is, as you can see, very messy.

Cheers,
Dave.

 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.