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


Hi Ard,

I was about to send you an answer similar to that of Jim Fuller when I saw his.

Here's what I had in my message that was not in his:


XSL is a FUNCTIONAL language (as opposed to PROCEDURAL). That means, among other things, that there is no concept of "before" and "after" (there is no time line).

i=i+1 is typically dependent on the time line: the PREVIOUS value of i is incremented of 1, and then it is stored (FUTURE value) into i.

That's why....


Antonio Fiol



Ard Schrijvers wrote:


Thanks a lot. This helps me a lot. I still don't understand, why in xsl simple programming code ( like for loops , not on the xml, but just like i=0 to 10) is not included. Also like date function, etc.
regards ard

-----Oorspronkelijk bericht-----
Van: James Fuller [mailto:james.fuller@o-idev.com]
Verzonden: 25 June 2002 11:50
Aan: xsl-list@lists.mulberrytech.com
Onderwerp: Re: [xsl] 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


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


.





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]