for
<?xml version="1.0"?>
<rows>
<row>
<total>1</total>
</row>
<row>
<total>2</total>
</row>
<row>
<total>3</total>
</row>
<row>
<total>4</total>
</row>
</rows>
try the following
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="rows">
<!--1
3
6
10
-->
<xsl:variable name="total-rows" select="count(row)"/>
<xsl:call-template name="print-sum">
<xsl:with-param name="initial" select="0"/>
<xsl:with-param name="counter" select="1"/>
<xsl:with-param name="total-rows" select="$total-rows"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="print-sum">
<xsl:param name="initial"/>
<xsl:param name="counter"/>
<xsl:param name="total-rows"/>
<xsl:if test="$counter <=$total-rows">
<xsl:variable name="row-val" select="row[position()=$counter]/total"/>
<xsl:variable name="sum" select="$initial+$row-val"/>
<xsl:value-of select="$sum"/>
<br/>
<xsl:call-template name="print-sum">
<xsl:with-param name="initial" select="$sum"/>
<xsl:with-param name="counter" select="$counter+1"/>
<xsl:with-param name="total-rows" select="$total-rows"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Untested..
HTH
Vasu
----- Original Message -----
From: "Jaime Stuardo" <jstuardo(_at_)security(_dot_)cl>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Wednesday, July 07, 2004 4:33 PM
Subject: [xsl] using preceding-sibling to calculate acummulated amount
Hi all...
I need to show in HTML a column of a table that shows the acummulated
quantity... If, for example, I have:
<row>
<total>1</total>
</row>
<row>
<total>2</total>
</row>
<row>
<total>3</total>
</row>
<row>
<total>4</total>
</row>
I want to show in HTML:
1
3
6
10
I tried:
total + preceding-sibling::total
but it didn't work.
Thanks
Jaime
--+------------------------------------------------------------------
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>
--+--