[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Sum in a Grouping
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> </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> </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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|