This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Adding numbers in xsl loop


----- Original Message -----
From: "Ard Schrijvers" <Ard@hippo.nl>
To: <xsl-list@lists.mulberrytech.com>
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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]