Subject: Re: [xsl] Accumulating Sum ( Sum Across Rows) From: "KUMAR NINGASHETTY" <kningashetty@xxxxxxxxxxxxxxxx> Date: Tue, 02 Apr 2002 18:47:29 -0500 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Manipulating file system , Steve Rosenberry | Thread | Re: [xsl] Accumulating Sum ( Sum Ac, Jeni Tennison |
RE: [xsl] Escaped Chars from DB dis, King Wilder | Date | RE: [xsl] Escaped Chars from DB dis, King Wilder |
Month |