xsl-list
[Top] [All Lists]

RE: for-each loops : calculations outside the loop, using data from inside

2004-04-20 21:54:40
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(_dot_)freeman(_at_)tolhurst(_dot_)com(_dot_)au] 
Sent: Wednesday, April 21, 2004 12:39 AM
To: 'xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com'
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


--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--




<Prev in Thread] Current Thread [Next in Thread>