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

Re: grouping and sum

Subject: Re: grouping and sum
From: dmitrik@xxxxxxxxxxxxxx
Date: Mon, 6 Dec 2004 13:36:12 -0500 (GMT-05:00)
xsl group sum
In a test version of the xml there are two Customers with the same name, and two different names.
The following xsl  displays  3 unique customers, which is correct, but the summation only 
works for the two single customers, not the instance with two trades for the same customer.
The current-group variable also does not seem to work - any idea what it requires? Would this
instance with the outer loop grouping follow your suggestion about  doing the summation in the 
inner loop?


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:key name="trade-to-step" match="Portfilio/Trade" use="Customer"/>
    
    <xsl:template match="/">
        <xsl:for-each select="Portfilio/Trade[generate-id() = generate-id(key('trade-to-step',Customer)[1])]">            
           <!-- <xsl:variable name="current-group" select="Trade[Customer= current()/Customer]"/>-->
           <xsl:variable name="current-group" select="Portfilio/Trade[Customer= current()]"/>
            <table>
                <tr>
                    <td colspan="4">
                        <b>
                            Code: <xsl:value-of select="Customer"/>	
			   Total: <xsl:value-of select="sum(Step/StepCharge_TTBlack)"/>
                        </b>
                    </td>                        
                </tr>
                   <tr>                     
                      <td>Amount</td>                      
                   </tr>                
                <xsl:for-each select="$current-group">
                    <tr>
                        <td>
                            <xsl:value-of select="Trade/NotionalRec"/>	
                        </td>                        
                    </tr>
                </xsl:for-each>
                <tr>
                    <td colspan="4">
                        <i>
                           <!-- Total: <xsl:value-of select="sum($current-group/NotionalRec)"/>-->
                           Total: <xsl:value-of select="sum(Step/StepCharge_TTBlack)"/>
                        </i>
                    </td>
                </tr>
            </table>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>


Thanks,
Dmitri


-----Original Message-----
From: David Carlisle <davidc@xxxxxxxxx>
Sent: Dec 6, 2004 11:18 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  grouping and sum


> Is it possible to group the whole xml document by the Customers node
> without hardcoding a specific customer? 

yes see jeni's site.
http://jenitennison.com/xslt/grouping

You may find it easiest not tp try doing grouping and summation all
inone step, but rather o a first pass that just does grouping, then use
easier XPaths that call sum() once all teh nodes that you want to sum
are grouped together.

David



________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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.