Subject: Re: [xsl] summing attributes problem From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx> Date: Fri, 27 Oct 2006 21:00:42 -0700 |
<total><xsl:value-of select="sum(current-group()[self::po/@cases])"/></total>
<total> <xsl:value-of select="sum(current-group()[self::po]/@cases)"/> </total>
-- Cheers, Dimitre Novatchev --------------------------------------- Truly great madness cannot be achieved without significant intelligence. --------------------------------------- To invent, you need a good imagination and a pile of junk ------------------------------------- You've achieved success in your field when you don't know whether what you're doing is work or play
Hi ya'll, I have a source file as such: <alldata> <load> <start>04/01/06 06:00</start> <stop>04/01/06 07:30</stop> <loadnum>300382</loadnum> </load> <po num="9865900" cases="206" /> <po num="9872940" cases="5" /> <po num="9877320" cases="290" /> <po num="9880590" cases="450" /> <po num="9880600" cases="418" /> <po num="9886650" cases="282" /> <load> <start>04/01/06 06:00</start> <stop>04/01/06 07:30</stop> <loadnum>300166</loadnum> </load> <po num="9873530" cases="630" /> <po num="9880740" cases="1008" /> ... </alldata> I want to group the po elements with their previous sibling load and sum the @cases to get:
<load> <loadnum>300382</loadnum> <start>04/01/06 06:00</start> <stop>04/01/06 07:30</stop> <po num="9865900" cases="206" /> <po num="9872940" cases="5" /> <po num="9877320" cases="290" /> <po num="9880590" cases="450" /> <po num="9880600" cases="418" /> <po num="9886650" cases="282" /> <total>1651</total> </load> <load> <loadnum>300166</loadnum> <start>04/01/06 06:00</start> <stop>04/01/06 07:30</stop> <po num="9873530" cases="630" /> <po num="9880740" cases="1008" /> <total>1638</total> </load>
But when I use the following stylesheet, the @cases don't sum and I get the following error using Saxon8.7 FORG0001: Can not convert string "" to a double... If I replace "sum" with "count" then it works.
<xsl:output method="xml"/> <xsl:template match="/cases"> <alldata> <xsl:for-each-group select="*" group-starting-with="load"> <load> <xsl:copy-of select="loadnum"/> <xsl:copy-of select="start"/> <xsl:copy-of select="stop"/>
<xsl:copy-of select="current-group()[self::po]"/> <total><xsl:value-of select="sum(current-group()[self::po/@cases])"/></total> </load> </xsl:for-each-group> </alldata> </xsl:template> </xsl:stylesheet>
Obviously I am using xslt2.0. Can someone explain what I am doing wrong? TIA
-- Cheers, Dimitre Novatchev --------------------------------------- Truly great madness cannot be achieved without significant intelligence. --------------------------------------- To invent, you need a good imagination and a pile of junk ------------------------------------- You've achieved success in your field when you don't know whether what you're doing is work or play
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] summing attributes problem, Kent Seegmiller | Thread | [xsl] Re: summing attributes proble, Kent Seegmiller |
[xsl] Re: summing attributes proble, Kent Seegmiller | Date | [xsl] Re: summing attributes proble, Kent Seegmiller |
Month |