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

Re: [XSL] Grouping and Sum problem - XSL 1.0

Subject: Re: [XSL] Grouping and Sum problem - XSL 1.0
From: "Mike Finch [Wasabeat]" <maikeru@xxxxxxxxxxxx>
Date: Wed, 30 Apr 2008 14:35:22 +0900
Re:  [XSL] Grouping and Sum problem - XSL 1.0
Yes, im trying to do an xsl:copy-of for the results but I cannot
get the sum's to add up when grouping the rows.  Im trying to sum
the grouped row's <royalty> <mechanicals> <taxes> <expenses>
elements however I can only get the sums to add up for the first
following sibling.  I need to add sums for all following siblings
which have the same <releaseid> and <order> as the row with they
type='RELEASE'

Below is the XSL properly indented.  Sorry about that.  

 <?xml version='1.0' encoding='utf-8' ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="RowByType" match="row"
use="concat(generate-id(preceding-sibling::row[1][type='RELEASE']
), releaseid)"/>
<xsl:template match="/*">
<xsl:copy>
<xsl:for-each select="row[type !=
'RELEASE'][count(.|key('RowByType',
concat(generate-id(preceding-sibling::row[type='RELEASE'][1]),
releaseid))[1] )= 1]">
	<xsl:copy>
		<xsl:copy-of select="id"/>
		<xsl:copy-of select="site"/>
		<xsl:copy-of select="order"/>
		<xsl:copy-of select="date"/>
		<xsl:copy-of select="userid"/>
		<type>
			<xsl:choose>
			<xsl:when
test="preceding-sibling::row[1][type='RELEASE']">
				<xsl:value-of
select="'RELEASE'"/>
			</xsl:when>
			<xsl:otherwise>
			<xsl:value-of select="'TRACK'"/>
			</xsl:otherwise>
			</xsl:choose>
		</type>
		<xsl:copy-of select="trackid"/>
		<xsl:copy-of select="title"/>
		<xsl:copy-of select="mixtitle"/>
		<xsl:copy-of select="artist"/>
		<xsl:copy-of select="remixer"/>
		<xsl:copy-of select="releaseid"/>
		<xsl:copy-of select="releasename"/>
		<xsl:copy-of select="catalognumber"/>
		<xsl:copy-of select="upc"/>
		<xsl:copy-of select="genre"/>
		<xsl:copy-of select="copyright"/>
		<xsl:copy-of select="composer"/>
		<xsl:copy-of select="lyricyst"/>
		<xsl:copy-of select="medley"/>
		<xsl:copy-of select="isrc"/>
		<xsl:copy-of select="chartid"/>
		<xsl:copy-of select="charttitle"/>
		<xsl:copy-of select="labelid"/>
		<xsl:copy-of select="labelname"/>
		<xsl:copy-of select="distributorid"/>
		<xsl:copy-of select="distributorname"/>
		<xsl:variable name="AddSum">
			<xsl:value-of
select="preceding-sibling::row[type='RELEASE'][1]/following-sibli
ng::row[1]/releaseid"/>
		</xsl:variable>
		<price>
		<xsl:choose>
		<xsl:when test="releaseid = $AddSum">
		<xsl:value-of select="sum(key('RowByType',
concat(generate-id(preceding-sibling::row[type='RELEASE'][1]),
releaseid))/price) +
preceding-sibling::row[type='RELEASE'][1]/price"/>
		</xsl:when>
		<xsl:otherwise>
		<xsl:value-of select="price"/>
		</xsl:otherwise>
		</xsl:choose>
		</price>
		<fee>
		<xsl:choose>
			<xsl:when test="releaseid = $AddSum">
			<xsl:value-of
select="sum(key('RowByType',
concat(generate-id(preceding-sibling::row[type='RELEASE'][1]),
releaseid))/fee) +
preceding-sibling::row[type='RELEASE'][1]/fee"/>
			</xsl:when>
			<xsl:otherwise>
			<xsl:value-of select="fee"/>
			</xsl:otherwise>
		</xsl:choose>
		</fee>
		<amount>
			<xsl:choose>
			<xsl:when test="releaseid = $AddSum">
			<xsl:value-of
select="sum(key('RowByType',
concat(generate-id(preceding-sibling::row[type='RELEASE'][1]),
releaseid))/amount) +
preceding-sibling::row[type='RELEASE'][1]/amount"/>
			</xsl:when>
			<xsl:otherwise>
			<xsl:value-of select="amount"/>
			</xsl:otherwise>
			</xsl:choose>
		</amount>
		<royalty>
			<xsl:choose>
			<xsl:when test="releaseid = $AddSum">
			<xsl:value-of
select="sum(key('RowByType',
concat(generate-id(preceding-sibling::row[type='RELEASE'][1]),
releaseid))/royalty) +
preceding-sibling::row[type='RELEASE'][1]/royalty"/>
			</xsl:when>
			<xsl:otherwise>
			<xsl:value-of select="royalty"/>
			</xsl:otherwise>
			</xsl:choose>
		</royalty>
		<mechanicals>
			<xsl:choose>
			<xsl:when test="releaseid = $AddSum">
			<xsl:value-of
select="sum(key('RowByType',
concat(generate-id(preceding-sibling::row[type='RELEASE'][1]),
releaseid))/mechanicals) +
preceding-sibling::row[type='RELEASE'][1]/mechanicals"/>
			</xsl:when>
			<xsl:otherwise>
		<xsl:value-of select="mechanicals"/>
			</xsl:otherwise>
			</xsl:choose>
		</mechanicals>
		<taxes>
			<xsl:choose>
			<xsl:when test="releaseid = $AddSum">
			<xsl:value-of
select="sum(key('RowByType',
concat(generate-id(preceding-sibling::row[type='RELEASE'][1]),
releaseid))/taxes) +
preceding-sibling::row[type='RELEASE'][1]/taxes"/>
			</xsl:when>
			<xsl:otherwise>
			<xsl:value-of select="taxes"/>
			</xsl:otherwise>
			</xsl:choose>
		</taxes>
		<expense>
			<xsl:choose>
			<xsl:when test="releaseid = $AddSum">
			<xsl:value-of
select="sum(key('RowByType',
concat(generate-id(preceding-sibling::row[type='RELEASE'][1]),
releaseid))/expense) +
preceding-sibling::row[type='RELEASE'][1]/expense"/>
			</xsl:when>
			<xsl:otherwise>
			<xsl:value-of select="expense"/>
			</xsl:otherwise>
			</xsl:choose>
		</expense>
	<xsl:copy-of select="year"/>
	<xsl:copy-of select="term"/>
	<xsl:copy-of select="state"/>
	</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

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.