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

summing attributes problem

Subject: summing attributes problem
From: "Kent Seegmiller" <hookjaw20@xxxxxxxxxxx>
Date: Fri, 27 Oct 2006 20:54:21 -0600
 summing attributes problem
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

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-2011 All Rights Reserved.