[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: using preceding-sibling to calculate acummulated a

Subject: Re: using preceding-sibling to calculate acummulated amount
From: "Vasu Chakkera" <vasucv@xxxxxxxxxxx>
Date: Wed, 7 Jul 2004 18:06:30 +0100
preceding sibling sum
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 &lt;=$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>
--+--


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.