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

Sum in a Grouping

Subject: Sum in a Grouping
From: Linda <binky_35@xxxxxxxx>
Date: Fri, 24 Aug 2001 09:43:57 -0400 (EDT)
xsl when sum
I am trying to sum a value in a group, in a cell, in a
table.  I am able to count the items and display only
the last one but I can't figure out how to sum the
numbers up.


XML snip:

<RECORD>
    <START_TIME>2001-06-19 09:00:07.0</START_TIME>
    <SHIPMENT_GID>WELKE.260</SHIPMENT_GID>
    <ORDER_RELEASE_GID>WELKE.ORDER BASE
ID-001</ORDER_RELEASE_GID>
   
<INVOLVED_PARTY_LOCATION_GID>CUSTOMER1.CUSTOMER1_SHIPFROM1</INVOLVED_PARTY_LOCATION_GID>
    <NET_AMOUNT_DUE>359.72</NET_AMOUNT_DUE>
    <CURRENCY_GID>CAD</CURRENCY_GID>
    <TOTAL_ACTUAL_COST>92.64</TOTAL_ACTUAL_COST>
   
<T_ACTUAL_COST_CURRENCY_GID>CAD</T_ACTUAL_COST_CURRENCY_GID>
    <TOTAL_ALLOC_COST>23.03</TOTAL_ALLOC_COST>
    <INVOICE_GID>WELKE.CB-20010710-0021</INVOICE_GID>
    <ORDER_BASE_GID>WELKE.ORDER BASE
ID</ORDER_BASE_GID>
</RECORD>

The count works like this:

<xsl:key name="records-by-party" match="RECORD"
use="INVOLVED_PARTY_LOCATION_GID"/>

<xsl:for-each select="RECORD[count(. |
key('records-by-party',
INVOLVED_PARTY_LOCATION_GID)[1]) = 1]">
							<hr/>
							<xsl:sort select="INVOLVED_PARTY_LOCATION_GID"
/><br />
							<br />
							<xsl:for-each select="key('records-by-party',
INVOLVED_PARTY_LOCATION_GID)">
							<xsl:sort select="START_TIME" />
							<xsl:choose>
							<xsl:when test='position()=last()'>
							<xsl:text>= </xsl:text><xsl:value-of
select="last()"/><br/>
							</xsl:when>
							<xsl:otherwise>
							<xsl:text>&#160;</xsl:text><br/>
							</xsl:otherwise>
							</xsl:choose>
							</xsl:for-each>
							</xsl:for-each>

Which displays nicely as:

=1

=8

=3

But I can't get the sum of the values in
'NET_AMOUNT_DUE', I keep getting each line in the
group displaying over again - or in this example case
- just the last one.

<xsl:for-each select="RECORD[count(. |
key('records-by-party',
INVOLVED_PARTY_LOCATION_GID)[1]) = 1]">
							<hr/>
							<xsl:sort select="INVOLVED_PARTY_LOCATION_GID"
/><br />
							<br />
							<xsl:for-each select="key('records-by-party',
INVOLVED_PARTY_LOCATION_GID)">
							<xsl:sort select="START_TIME" />
							<xsl:choose>
							<xsl:when test='position()=last()'>
							<xsl:text>= </xsl:text><xsl:value-of
select="NET_AMOUNT_DUE"/><br/>
							</xsl:when>
							<xsl:otherwise>
							<xsl:text>&#160;</xsl:text><br/>
							</xsl:otherwise>
							</xsl:choose>

							</xsl:for-each>
							</xsl:for-each> 

Please help, if you know!  I have exhausted all books
and web sites!

Thanks in advance.

Linda

_______________________________________________________
Do You Yahoo!?
Get your free @yahoo.ca address at http://mail.yahoo.ca

 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.