xsl-list
[Top] [All Lists]

Re: Grouping by key

2004-11-12 06:15:02
I think a key is easiest then...

    <xsl:key name="ordervalues-by-town" match="*[(_at_)colno = 3]" 
use="../*[(_at_)colno  =2]" />

Though it seems the following might work just as well:

    <xsl:key name="ordervalues-by-town" match="ordervalue" use="../town" />

And when you want to insert the sum for a town, use:

    <xsl:value-of select="sum(key('ordervalues-by-town', *[(_at_)colno = 2]))" 
/>
or
    <xsl:value-of select="sum(key('ordervalues-by-town', town))" />

Grtz,
Geert

Hi,

Geert wrote:

Are you trying to display the sum of all colno 3 elements? try

'sum(//*[(_at_)colno=3])' instead.

If you want the cumulative of the 'above', you could try '*[(_at_)colno = 3]

+ sum(preceding-sibling::account/*[(_at_)colno=3])'..

Thanks Geert. Your suggestions work but what I want to do is sum up that column values matching the key. Like when I am grouping the documents by Town, I want to sum up the 3rd column for that town. Please check my xml document format and required output format.

Asssuming my xml document is
<documents>
<account>
<accountnumber colno="0">0001</accountnumber>
<companyname colno="1">ABC Ltd</companyname>
<town colno="2">Ford</town>
<ordervalue colno="3">115.49</ordervalue>
<postcode colno="4">FD13QG</postcode>
</account>
<account>
<accountnumber colno="0">0002</accountnumber>
<companyname colno="1">XYZ Ltd</companyname>
<town colno="2">Ford</town>
<ordervalue colno="3">120.49</ordervalue>
<postcode colno="4">XY13QG</postcode>
</account>
<account>
<accountnumber colno="0">0003</accountnumber>
<companyname colno="1">HAM Ltd</companyname>
<town colno="2">Hamtown</town>
<ordervalue colno="3">110.34</ordervalue>
<postcode colno="4">HA13QG</postcode>
</account>
</documents>

I want an output like

Ford 235.98 0001 ABC Ltd 115.49 FD13QG
        0002    XYZ Ltd         120.49  XY13QG

Hamtown                 110.34
        0003    HAM Ltd 110.34  HA13QG

Thanks.


--
Geert(_dot_)Josten(_at_)Daidalos(_dot_)nl
IT-consultant at Daidalos BV, Zoetermeer (NL)

http://www.daidalos.nl/
tel:+31-(0)79-3316961
fax:+31-(0)79-3316464

GPG: 1024D/12DEBB50

--~------------------------------------------------------------------
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>
--~--



<Prev in Thread] Current Thread [Next in Thread>