Re: [xsl] Keeping a running total? (Redo)

Subject: Re: [xsl] Keeping a running total? (Redo)
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Tue, 11 Jul 2006 12:36:46 -0700
On 7/11/06, Steve <subsume@xxxxxxxxx> wrote:
I will cross that bridge when I get to it. I'm having a hard enough
time getting help for the first problem.

When I solve how to keep a running total, it will be easy to add
whatever is left over to the next quota.

Then here's the running-total part:


This xslt transformation:

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:f="http://fxsl.sf.net/";
 exclude-result-prefixes="f"

 <xsl:import href="../f/func-scanl.xsl"/>
 <xsl:import href="../f/func-Operators.xsl"/>

<xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/">
    <xsl:for-each select="f:scanl1(f:add(), /*/*/@capacity)">
     <xsl:value-of select="concat(., ', ')"/>
    </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>

when applied against the provided source xml document:

<xml>
<factory x="A" capacity = "3" />
<factory x="B" capacity= "5" />
 <factory x="C" capacity = "3" />
 <factory x="D" capacity = "2" />
 <factory x="E" capacity = "2" />
 ...etc...
</xml>

produces the wanted result (the list of running totals):

3, 8, 11, 13, 15,

Current Thread