|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: using preceding-sibling to calculate acummulated a
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@xxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, July 07, 2004 4:33 PM
Subject: 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@xxxxxxxxxxxxxxxxxxxxxx>
--+--
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








