Re: [xsl] Adding numbers in xsl loop

Subject: Re: [xsl] Adding numbers in xsl loop
From: "Vasu Chakkera" <vasucv@xxxxxxxxxxx>
Date: Tue, 25 Jun 2002 10:22:23 +0000
I have a question...
Refering to Ard's problem,
since position() would give the position of the current node,
cudnt we then take this as a variable counter and add it up to what ever u want to add??


like
..in the example... given by Ard,
if the required result follows the logic
$totaalX+i ( where i = 1 to no of times loop runs,)

Then cudnt we just do
<xsl:value-of select="concat($totaalX,position())"/> in the for loop
to produce a result that is concatenated with a counter ( from 1 to end of loop position)


( as long as this is what Ard needs.... )
Vasu



From: "James Fuller" <james.fuller@xxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: Re: [xsl] Adding numbers  in xsl loop
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 &lt;= $count">
<!--    body of the loop goes here    -->
 </xsl:if>
 <xsl:if test="$i &lt;= $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




_________________________________________________________________
Join the world?s largest e-mail service with MSN Hotmail. http://www.hotmail.com



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread