[xsl] for-each loops : calculations outside the loop, using data from i nside

Subject: [xsl] for-each loops : calculations outside the loop, using data from i nside
From: Chris Freeman <chris.freeman@xxxxxxxxxxxxxxx>
Date: Wed, 21 Apr 2004 14:39:17 +1000
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