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

An XSLT equivalent of the SQL SUM and GROUP BY operati

Subject: An XSLT equivalent of the SQL SUM and GROUP BY operations ?
From: Andy Tarpey <Andy_Tarpey@xxxxxxxxxxxxxxxx>
Date: Mon, 21 May 2001 13:58:43 +0100
sql sum
Can anyone suggest how I might go about performing a transformation which is
the logical equivalent of a SQL statement like :

	SELECT Account, Date, SUM(Amount)
	FROM ...
	GROUP BY Account, Date

An example of the type of transformation I am trying to achieve (which
matches the above SQL) is given below. 

XML input :
<line>
<Account>64001</Account><Date>01/02/91</Date><Amount>50</Amount>
</line>
<line>
<Account>64001</Account><Date>01/02/91</Date><Amount>70</Amount>
</line>
<line>
<Account>64002</Account><Date>12/03/91</Date><Amount>60</Amount>
</line>
<line>
<Account>64002</Account><Date>01/02/91</Date><Amount>30</Amount>
</line>
<line>
<Account>64002</Account><Date>12/03/91</Date><Amount>90</Amount>
</line>

XML output :
<line>
<Account>64001</Account><Date>01/02/91</Date><Amount>120</Amount>
</line>
<line>
<Account>64002</Account><Date>01/02/91</Date><Amount>30</Amount>
</line>
<line>
<Account>64002</Account><Date>12/03/91</Date><Amount>150</Amount>
</line>

The transformation should sum all the Amounts for each matching Date within
each matching Account (i.e. Account 64001 shrinks to a single line as both
the dates are the same, but Account 64002 shrinks to two lines - one with
the sum of the amounts for 01/02/91 and one with the sum of the amounts for
12/03/91).

Any hints/suggestions/solutions for the specific example quoted or a more
generic solution (where parameters specify the nodes to group by and their
precedence) would be gratefully appreciated.


 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.