[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|