p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   Sum function and XPath problems (http://p2p.wrox.com/showthread.php?t=44416)

tslag June 23rd, 2006 03:36 PM

Sum function and XPath problems
Ok, sorry for all the posts, but this is very hard for me to get for some reason. I want to sum several dozen values and present them, but the sum function is returning very small numbers, perhaps just the first number it comes to. Again, I think this is from my grouping troubles. Here is the code:
source file:





Where there are hundreds of <pavement...> nodes and several different <Inspected_x0020z_Use> values.
and the xsl file:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="dataroot">
<main caption="Table Title" headertextfont="Arial" headertextcolor="0xFFFFFF" rowtextfont="Arial" rowtextcolor="0x000000" headercolor="0x5372aa" rowcolor="0xFFFFFF" altrowcolor="0xcccccc">

    <xsl:for-each-group select="pavement_x0020_Conditions" group-by="Inspected_x0020_Use">
      <xsl:sort select="Inspected_x0020_Use"/>
    <Use><xsl:value-of select="Inspected_x0020_Use"/></Use>
    <Area><xsl:value-of select="sum(current-group()/Inspected_x0020_Area)"/></Area>

I need to get the area of each Inspected Use, of which there are several types. I used a method very similar to what was suggested in my previous post, and it doesn't seem to add anything. I think I am just pointing at the wrong thing. Any ideas?

tslag June 26th, 2006 10:16 AM

Alright, I feel quite foolish. The sum function was working, but further along in the source xml document that I was processing there were some large numbers getting added in, so the numers that resulted were actually things like 10782.34005E7. Notice the "E". I tried the same thing with smaller numbers and it worked fine. Sorry to anyone who put some time into this.

mhkay June 26th, 2006 10:23 AM

In XSLT 2.0, numbers in "scientific" notation are accepted.

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference

All times are GMT -4. The time now is 01:09 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.