Subject: Re: [xsl] [XSL] Grouping and Sum problem - XSL 1.0 From: "Mike Finch" <maikeru@xxxxxxxxxxxx> Date: Thu, 1 May 2008 21:40:17 +0900 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] xsltproc/LibXSLT - non-co, Liam Quin | Thread | Re: [xsl] Grouping and Sum problem , Florent Georges |
Re: [xsl] Re: Checking for Cycles i, Darcy Parker | Date | Re: [xsl] Grouping and Sum problem , Florent Georges |
Month |