[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] for-each loops : calculations outside the loop, using data from inside
Subject: RE: [xsl] for-each loops : calculations outside the loop, using data from inside From: "Kenny Akridge" <kenny@xxxxxxxxxxxxxxxxx> Date: Wed, 21 Apr 2004 00:54:40 -0400 |
My advice is to use a recursive template. Take a look at this for help on recursion if you need it: http://www-106.ibm.com/developerworks/xml/library/x-xslrecur/ Also, not sure if it applies, but make sure you account for a StartTime of 2200 and an end time of 0400. This would give you -1800. In this case, add 2400 to 0400 and then subtract the 2200 = 600. -----Original Message----- From: Chris Freeman [mailto:chris.freeman@xxxxxxxxxxxxxxx] Sent: Wednesday, April 21, 2004 12:39 AM To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx' Subject: [xsl] for-each loops : calculations outside the loop, using data from inside I'm sure this will be simple for a more experienced xsl coder. I've removed the bulk of my code, leaving only the relevant parts. (removed code designated by --- ) I want to add a number from each "for-each" run-thru, to a total that will be displayed once the loop has completed. Can't find the solution anywhere! See comments in code below! Cheers :) <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="ptimetable"> <html> --- <xsl:for-each select="class"> --- <td> <xsl:value-of select="time/timestart"/> </td> <td> <xsl:value-of select="time/timeend"/> <!-- Time in 24 hour clock--> <xsl:variable name="temp_length"> <xsl:value-of select="(number(time/timeend)-number(time/timestart)) * 0.6"/> <!-- Calc the time, convert to minutes--> </xsl:variable> </td> --- </xsl:for-each> <!-- end of the loop --> </table> The total time of all classes is : <xsl:variable name="cum_total"/> <!-- How do i calculate cumulative total from data in the loop? <!--- HERE - I WANT TO DISPLAY THE TOTAL TIME OF ALL LISTED "subject"s--> <!--- EACH TIME THE temp_length IS CALCULATED, I NEED TO ADD IT TO A CUMULATIVE TOTAL, PRESUMABLY OUTSIDE THE LOOP! --> <!--- HELP! --> </html> </xsl:template> </xsl:stylesheet> Chris Freeman Tolhurst Noall 29/35 Collins Street, Melbourne 03 9242 4021
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] for-each loops : calculations, Chris Freeman | Thread | [xsl] Excluding too much in nested , Ragulf Pickaxe |
[xsl] for-each loops : calculations, Chris Freeman | Date | Re: [xsl] Carriage returns in attri, G. Ken Holman |
Month |
Keywords