Subject: Re: [xsl] [XSL] Grouping and Sum problem - XSL 1.0 From: "Mike Finch [Wasabeat]" <maikeru@xxxxxxxxxxxx> Date: Wed, 30 Apr 2008 14:35:22 +0900 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] [XSL] Grouping and Sum pr, Michael Ludwig | Thread | Re: [xsl] [XSL] Grouping and Sum pr, Michael Ludwig |
[xsl] Re: Working with Collections, XSL-List Owner | Date | Re: [xsl] Problem with Safari?, Michael Müller-Hille |
Month |