[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: summing attributes problem

Subject: Re: summing attributes problem
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Fri, 27 Oct 2006 21:00:42 -0700
Re:  summing attributes problem
Just replace:

  <total><xsl:value-of
select="sum(current-group()[self::po/@cases])"/></total>

with:


<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



On 10/27/06, Kent Seegmiller <hookjaw20@xxxxxxxxxxx> wrote:
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.