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

Re: Problem accumulating values.

Subject: Re: Problem accumulating values.
From: Andrew Welch <andrew.j.welch@xxxxxxxxx>
Date: Thu, 3 Mar 2011 11:43:58 +0000
Re:  Problem accumulating values.
> The _problem_ is, that I need to calculate at the end of each week, the
> total duration time of all the tasks for that week (week = duration time
> of task 1 + duration time of task 2 + duration time of task 3...). I
> have tried using the sum() function in different ways but did not
> worked. I also tried creating a new tag inside my 'task' node, but it
> just does not work, sum() keeps on appending the values instead of
> summing them.

Sum is correct, for example:

sum(for $x in //task return $x/xs:dateTime(@end) - $x/xs:dateTime(@start))

returns

PT1M28S

> This is how my .XSLT file looks like: http://pastebin.com/jLV2EHFa
>
> and this is the result generated file: http://pastebin.com/dDpJVqLL
>
> As you see, the results are appended and not summed, which is what I
> need.

You are working at the <task> level, so you are outputting the sum of
just that 1 task.  You need to operate at the week level, eg change
the for-each in:

<xsl:template match="year/week">
  ....
  <xsl:for-each select="day/task">
    <xsl:call-template name="total_duration"/>
  </xsl:for-each>

to just:

<xsl:value-of select="sum(for $x in task return $x/xs:dateTime(@end) -
$x/xs:dateTime(@start))/>

(well, make it a variable and then do your formatting as you have done already)


-- 
Andrew Welch
http://andrewjwelch.com

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.