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

Re: Accumulating Sum ( Sum Across Rows)

Subject: Re: Accumulating Sum ( Sum Across Rows)
From: "KUMAR NINGASHETTY" <kningashetty@xxxxxxxxxxxxxxxx>
Date: Tue, 02 Apr 2002 18:47:29 -0500
sum of rows
Here is the XSL snippet i am using and adopting the sum() function you specified . It doesnt give me the sum rather
it gives me the concatenation of numbers across the rows... For example in this XML example it gives 41 instead of
5 ( 4+1) 
can you throw some solution on this again to calculate SUM across ROWS  ..I am attaching XML again if anyone wanna
take a look at it ...
Note : pete , I have changed XML slightly to look simple ...

<!-- XSL snippet -->

<xsl:key name="distinct-region"  match="//company/vehicle/region/region_name"  use="text()"/>

<xsl:template match="/" >

 <xsl:for-each select="//company/vehicle/region/region_name[generate-id()=generate-id(key('distinct-region', text()))]">

    <xsl:variable name="sumN">
           <xsl:for-each select="key('distinct-region', text())">

	     <xsl:variable name="uid"	select="ancestor::vehicle/@id"/>
                    <xsl:value-of select="sum(ancestor::data/review/vehicle[@idref=$uid)"/>

        </xsl:for-each>
     </xsl:variable>

     <xsl:value-of select="$sumN"/>

 </xsl:for-each>
</xsl:template>


<!--  XML -->
<data>
 <company>
 	<vehicle id="768">
		<region >
		     <region_name><![CDATA[Region 4]]></region_name>
		</region>
		<company_name><![CDATA[ABC Inc.]]></company_name>
		<status><![CDATA[t]]></status>
	</vehicle>
	<vehicle id="232">
		<region >
		      <region_name><![CDATA[Region 4]]></region_name>
		</region>
		<company_name><![CDATA[BBC Inc.]]></company_name>
		<status><![CDATA[f]]></status>
	</vehicle>
 </company>
 <review>
 	<vehicle idref="768">1</vehicle>
 	<vehicle idref="232">4</vehicle>
 </review>
</data> 

HTML o/P
―-----------------

  Comp          stat	  typN    Total
    -----	      -----	  ----        -----
    ABCInc        t	   1	5 
    BBCInc        f	   4	5	

( i am having probs calculating Total )

Thanx again 
-Kumar




>>> j3322ptm@xxxxxxxx 04/02/02 03:00PM >>>
KUMAR NINGASHETTY wrote:
...
>        Comp        stat	  typN    Total
>         -----	-        -----	  ----        -----
>       ABCInc        t	   1	5 
>       BBCInc        f	   4	5	
> 
> Problem :  I could populate first 3 columns..To populate the
 > 4th column 'Total' which is sum frm each row of column 'typeN'

Check whether the sum() function solves your problem.
Try something like
   <xsl:variable name="totalN" select="vehicle/count[type='N']"/>
and use the variable.

J.Pietschmann


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list 



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.