[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: increment variable with xsl:for-each
Subject: Re: increment variable with xsl:for-each
From: Tuan Luu <tuanluu@xxxxxx>
Date: Fri, 26 Mar 2004 23:18:49 +0100
|
Thanks David.
M. David Peterson wrote:
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 <= 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: 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|