Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 20th, 2005, 09:38 AM
Rivky
Guest
 
Posts: n/a
Default XSL: SUM BY GROUP

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!

  #2  
Old July 20th, 2005, 09:38 AM
Dimitre Novatchev
Guest
 
Posts: n/a
Default Re: SUM BY GROUP

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" <rasapir81@aol.com> wrote in message
news:1116356189.560882.37980@g43g2000cwa.googlegro ups.com...[color=blue]
> 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!
>[/color]


 

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles