Link to home
Start Free TrialLog in
Avatar of lunky
lunky

asked on

xslt sum / group

<orderform id="1">
    <Items quantity="1" productid="AAA" cy_lineitem_total="72" >
       <saved_orderlevel_discounts_applied cy_discount_amount="30" discount_name="MVP Discount" discount_id="243"/>
       <saved_orderlevel_discounts_applied cy_discount_amount="10" discount_name="VIP Discount" discount_id="2"/>
    </Items>
    <Items quantity="1" productid="AAB" cy_lineitem_total="100.2" >
       <saved_orderlevel_discounts_applied cy_discount_amount="20" discount_name="MVP Discount" discount_id="243"/>
    </Items>
</orderform>

how can i transform the above xml into  the fragment below?
Notice that the saved_orderlevel_discounts_applied nodes have been grouped by discount_id and the cy_discount_amount has been summed.  
I need to do it in xslt, I am open to using the msxml extensions (? node-set() ?) but I can't use inline functions.

<orderform id="1">
    <Items quantity="1" productid="AAA" cy_lineitem_total="72" />
    <Items quantity="1" productid="AAB" cy_lineitem_total="100.2" />
       <saved_orderlevel_discounts_applied cy_discount_amount="50" discount_name="MVP Discount" discount_id="243" />
       <saved_orderlevel_discounts_applied cy_discount_amount="10" discount_name="VIP Discount" discount_id="2"/>
</orderform>
ASKER CERTIFIED SOLUTION
Avatar of Thogek
Thogek
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In your XMLs above, it appears that the saved_orderlevel_discounts_applied elements are grouped regardless of which Items element each originally belonged to.  Is this intentional?  (Or should they be grouped within each Items element?)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
*knock* *knock* anybody home?