Subject: Re: [xsl] Adding numbers in xsl loop From: "James Fuller" <james.fuller@xxxxxxxxxx> Date: Tue, 25 Jun 2002 10:49:34 +0100 |
----- Original Message ----- From: "Ard Schrijvers" <Ard@xxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Tuesday, June 25, 2002 10:27 AM Subject: [xsl] Adding numbers in xsl loop > > Perhaps somebody can help me with the following: > > I want in an xsl:for-each loop to add a found value to a certain variable. Something like this: > > <xsl:for-each select="projects/project[medewerker[login=$loginMatch]]"> > <xsl:variable name="currentPro" select="name"/> > <xsl:variable name="totaalX" select="sum(../../hours/entry[login=$loginMatch][date/year=$jaarX][date/mont h=$maandX][projectname=$currentPro]/duration)"/> > (now i want something like, so that absTotal get's in the loop everytime the value of totaalX plus the value of itself:) > <xsl:variable name="absTotal" select="$absTotal + $totaalX"/> > </xsl:for-each> > > Apparently, this does not work in xsl. I can't figure out, how to use a basic programming issue like i = i + 1 in a loop??????????? hehe, another customer ! u cant do x=x+1 loops with XSLT, because once u set a var it cannot change ! u can get around this quite easily by having a named template and call it recursively eg. taken straight from cooktop <!-- Use: include this call with the number of iterations This sample will loop from 1 to 10 including 1 and 10 --> <xsl:call-template name="for.loop"> <xsl:with-param name="i">1</xsl:with-param> <xsl:with-param name="count">10</xsl:with-param> </xsl:call-template> <!-- Rename "old name" elements to "new name" --> <xsl:template name="for.loop"> <xsl:param name="i"/> <xsl:param name="count"/> <xsl:if test="$i <= $count"> <!-- body of the loop goes here --> </xsl:if> <xsl:if test="$i <= $count"> <xsl:call-template name="for.loop"> <xsl:with-param name="i"> <!-- Increment index--> <xsl:value-of select="$i + 1"/> </xsl:with-param> <xsl:with-param name="count"> <xsl:value-of select="$count"/> </xsl:with-param> </xsl:call-template> </xsl:if> </xsl:template> hth, jim fuller XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Adding numbers in xsl loop, Ard Schrijvers | Thread | Re: [xsl] Adding numbers in xsl lo, Jeni Tennison |
[xsl] Adding numbers in xsl loop, Ard Schrijvers | Date | Re: [xsl] Sorting issue, Jeni Tennison |
Month |