RE: [xsl] increment variable with xsl:for-each

Subject: RE: [xsl] increment variable with xsl:for-each
From: "M. David Peterson" <m.david@xxxxxxxxxx>
Date: Fri, 26 Mar 2004 11:33:03 -0700
Using a recursive call-template does the trick..  Basically you call a
template from within one template with a parameter that is set to the
beginning of the increment.  From within that template you test to see
if the value of the param meets whatever your criteria is and if it does
you output whatever it is you want and then call the same template, this
time incrementing the value of the included parameter by whatever you
want by adding the necessary arithmetic within the select statement e.g.
"$value + 1"

So this XSLT:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
  <xsl:call-template name="incrementValue">
    <xsl:with-param name="value">1</xsl:with-param>
  </xsl:call-template>
</xsl:template>
<xsl:template name="incrementValue">
  <xsl:param name="value"/>
    <xsl:if test="$value &lt;= 10">
      <xsl:value-of select="$value"/>
      <xsl:call-template name="incrementValue">
        <xsl:with-param name="value" select="$value + 1"/>
      </xsl:call-template>
    </xsl:if>
</xsl:template>
</xsl:stylesheet>

Will output:

12345678910

Best of luck!

<M:D/>

-----Original Message-----
From: Tuan Luu [mailto:tuanluu@xxxxxx] 
Sent: Friday, March 26, 2004 10:59 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] increment variable with xsl:for-each

hello 
I'm looking for a code to increment a variable in xsl:for-each loop

I ended up here: 

<xsl:variable name="a">1</xsl:variable>

<xsl:for-each select="name">

<xsl:value of select="{$a+1}"/>
<xsl:value of select="{$a}"/>

</xsl:for-each>


thanks for any answer


-- 
+++ NEU bei GMX und erstmalig in Deutschland: T\V-gepr|fter Virenschutz
+++
100% Virenerkennung nach Wildlist. Infos: http://www.gmx.net/virenschutz

Current Thread