[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" <maikeru@xxxxxxxxxxxx>
Date: Thu, 1 May 2008 21:40:17 +0900
Re:  [XSL] Grouping and Sum problem - XSL 1.0
Thank you for your help so far.  My many apologies for the
multiple posting in this board aswell as I was unaware of the
delay between mail and posting.  

Ive tried incorporating the sum solution your assisted me with
however im still only getting a sum with the first following
sibling. Im trying to sum the total royalty for both the row
which is type RELEASE as well as the following siblings royalties
which have the same releaseid as well as same order number as the
preceding RELEASE row.  Please see the desired output on the
bottom of this posting.  I have minimized both the input, desired
output as well as the xsl im having a problem with, so if you can
take a look once again I would be extremely thankful.

Input

<?xml version="1.0" encoding="UTF-8"?>
<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<row>
		<order>7903</order>
		<type>TRACK</type>
		<releaseid>12302</releaseid>
		<royalty>175.76</royalty>
	</row>
	<row>
		<order>7927</order>
		<type>RELEASE</type>
		<royalty>351.52</royalty>
	</row>
	<row>
		<order>7927</order>
		<type>TRACK</type>
		<releaseid>12560</releaseid>
		<royalty>-11.011</royalty>
	</row>
	<row>
		<order>7927</order>
		<type>TRACK</type>
		<releaseid>12560</releaseid>
		<royalty>-11.011</royalty>
	</row>
	<row>
		<order>7927</order>
		<type>TRACK</type>
		<releaseid>12367</releaseid>
		<royalty>109.75</royalty>
	</row>
</document>

XSLT text

<?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="order"/>
					<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="releaseid"/>
						<!-- This is the
area which im having trouble with.  It will not sum for all of
the following siblings with the same order as the preceding
sibling and same releaseid as all following siblings -->
						<royalty>
	
<xsl:choose>
	
<xsl:when test="preceding-sibling::row[1][type='RELEASE']">
	
<xsl:value-of
select="preceding-sibling::row[1][type='RELEASE']/royalty +
following-sibling::row[releaseid = current()/releaseid and
order=current()/order]/royalty"/>
</xsl:when>
	
<xsl:otherwise>
	
<xsl:value-of select="royalty"/>
	
</xsl:otherwise>
	
</xsl:choose>
						</royalty>
				</xsl:copy>
			</xsl:for-each>
		</xsl:copy>
	</xsl:template>
</xsl:stylesheet>


Below is the desired output

<?xml version="1.0" encoding="UTF-8"?>
<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<row>
		<order>7903</order>
		<type>TRACK</type>
		<releaseid>12302</releaseid>
		<royalty>175.76</royalty>
	</row>
	<row>
		<order>7927</order>
		<type>RELEASE</type>
		<releaseid>12560</releaseid>
		<!-- below is the royalty sum i cannot create -->
		<royalty>329.498</royalty>
	</row>
	<row>
		<order>7927</order>
		<type>TRACK</type>
		<releaseid>12367</releaseid>
		<royalty>109.75</royalty>
	</row>
</document>

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.