Subject: Re: [xsl] Re: Keeping a running total? From: Andrew Franz <afranz0@xxxxxxxxxxxxxxxx> Date: Thu, 13 Jul 2006 02:07:02 +1000 |
<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>
<xsl:template match="xml"> <xsl:apply-templates select="factory"> <xsl:with-param name="leftW" select="$Widget_quota" /> <xsl:with-param name="leftG" select="$Gadget_quota" /> <xsl:apply-templates select="factory"> </xsl:template>
<xsl:template match="factory"> <!-- running totals of capacity already used --> <xsl:param name="used">0</xsl:param> <xsl:param name="usedW">0</xsl:param> <xsl:param name="usedG">0</xsl:param> <!-- running totals of quota not used --> <xsl:param name="leftW">0</xsl:param> <xsl:param name="leftG">0</xsl:param>
<xsl:otherwise> <xsl:apply-templates select="."> <xsl:with-param name="used" select="@capacity" /> <xsl:with-param name="usedW" select="$usedW" /> <xsl:with-param name="usedG" select="$usedG" /> </xsl:apply-templates> </xsl:otherwise>
</xsl:choose> </xsl:template>
This is one possible solution, however it's time complexity is O(N^2) and can be unacceptable for producing intermediate results from an operation over a list of N items.
A recursive solution (such as using the FXSL scanl() template/function) can have a O(N) complexity.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Re: Keeping a running tot, Dimitre Novatchev | Thread | Re: [xsl] Re: Keeping a running tot, Steve |
[xsl] Outputting a complete schema , Christopher Foley | Date | AW: [xsl] RSS 2.0 to RSS 1.0 XSLT p, Huditsch, Roman \(LN |
Month |