|
[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
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>
|
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
|

![Re: [XSL] Grouping and Sum problem - XSL 1.0](/images/get_stylus.gif)




