Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: "Mike Finch" <maikeru@------------>
To:
Date: 5/1/2008 12:41:00 PM
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>


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent