Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSL: SUM BY GROUP

Reply
Thread Tools

XSL: SUM BY GROUP

 
 
Rivky
Guest
Posts: n/a
 
      05-17-2005
Hi. I have XML that is something like this?

<ROW>
<SYMBOL>A</SYMBOL>
<AMOUNT>10</AMOUNT>
</ROW>
<ROW>
<SYMBOL>A</SYMBOL>
<AMOUNT>20</AMOUNT>
</ROW>
<ROW>
<SYMBOL>B</SYMBOL>
<AMOUNT>10</AMOUNT>
</ROW>
<ROW>
<SYMBOL>C</SYMBOL>
<AMOUNT>50</AMOUNT>

</ROW>
<ROW>
<SYMBOL>C</SYMBOL>
<AMOUNT>60</AMOUNT>
</ROW>

I would like to get the SUM of AMOUNT based on the Symbol. Is there any
way to do this dynamically, using XSL/XSLT without having to specify
SYMBOL = 'A'. Rather something like For each Symbol, sum the Amounts.

Thanks in advance!

 
Reply With Quote
 
 
 
 
Dimitre Novatchev
Guest
Posts: n/a
 
      05-17-2005
First find the distinct values for SYMBOL, using a grouping method (such as
the Muenchian method,
see: http://www.jenitennison.com/xslt/grouping/)

Then iterate over these distinct values and produce the following value:

sum($yourDocument//ROW[SYMBOL = current()]/AMOUNT)

Of course, you may be using keys, in which case you'll be evaluating
something like this:

sum(key('kSymByVal', $aDistinctValue)/../AMOUNT)


Cheers,
Dimitre Novatchev

"Rivky" <> wrote in message
news: ups.com...
> Hi. I have XML that is something like this?
>
> <ROW>
> <SYMBOL>A</SYMBOL>
> <AMOUNT>10</AMOUNT>
> </ROW>
> <ROW>
> <SYMBOL>A</SYMBOL>
> <AMOUNT>20</AMOUNT>
> </ROW>
> <ROW>
> <SYMBOL>B</SYMBOL>
> <AMOUNT>10</AMOUNT>
> </ROW>
> <ROW>
> <SYMBOL>C</SYMBOL>
> <AMOUNT>50</AMOUNT>
>
> </ROW>
> <ROW>
> <SYMBOL>C</SYMBOL>
> <AMOUNT>60</AMOUNT>
> </ROW>
>
> I would like to get the SUM of AMOUNT based on the Symbol. Is there any
> way to do this dynamically, using XSL/XSLT without having to specify
> SYMBOL = 'A'. Rather something like For each Symbol, sum the Amounts.
>
> Thanks in advance!
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Query to Linq (Group By and Sum) Alex Sauceda ASP .Net 6 02-04-2008 10:26 PM
Packet retransmits and bad check sum on ethereal capture Newbie72 Cisco 4 03-10-2006 01:52 PM
Calculate Running sum of 4 text boxes on client side script? Davisro ASP .Net 2 04-20-2004 08:18 PM
Javascript into ASP.Net Simple example wanted.. Sum Textboxes client side Davisro ASP .Net 4 04-10-2004 08:42 AM
DataGrid: how to have a footer row dynamically sum data Roger Moore ASP .Net 0 07-07-2003 05:27 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57