Sum Function Problem
I'm Jake, newbie to xml/xslt and this forum...thanks to all who give their time to help others. I've read much and viewed many tutorials in an effort to solve my own problems, but 1 eludes me. Running Win7, Net 2.0 (I think)...my apps(MS Flight Simulator and SimVar) auto generate the xml, whose format matches nothing I've seen on the Web:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href='MissionProfile.xsl'?>
<MissionProfile>
<Profile name="SIMVAR_VERSION" value="V1.0.3537.0"/>
<Gather>
<Stat ID="" Name="GPS WP CROSS TRK" Unit="decimile">
<Point Time="4092177244">1.30295</Point>
<Point Time="4092177254">-2.30295</Point>
<Point Time="4092177264">3.30295</Point>
<Point Time="4092177274">-4.30295</Point></Stat></Gather>
<State/>
<Checksum>F6C0FB45AB5969A20043022EE9FFB8D4</Checksum></MissionProfile>
The Point nodes are created automatically by the apps as one flies the simulator. The @Time is a time stamp for the Point value, which is a measure, right (-) or left(+), of the planned flightpath.
I wish to average ALL Points, but since some are -, I can't simply combine and then divide by the count (or even better get avg function to work). I must first sum all negative values, multiply sum by -1, add back to the sum of the positive values and then divide by the count.
Here's what works (code lists all values of Point):
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
<xsl:template match="/MissionProfile">
<html>
<h2>Here's your average Flight Plan deviation in decimiles</h2>
<body>
<xsl:for-each select="Gather/Stat/Point">
<xsl:value-of select="."/><xsl:text>, </xsl:text>
</xsl:for-each>
<br/>
This works (Sums ALL values of Point):
<xsl:for-each select="Gather/Stat">
<xsl:text>SumOfAll = </xsl:text><xsl:value-of select="sum(Point)" />
</xsl:for-each>
<br/>
This too works (Lists all values of Point that are -):
<xsl:text>ListOfAllLT0 = </xsl:text>
<xsl:for-each select="Gather/Stat/Point">
<xsl:if test=".<0">
<xsl:value-of select="."/><xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
<br/>
Here's my problem (Summing all those - values of Point)...no error, just blank:
<xsl:for-each select="Gather/Stat">
<xsl:text>SumOfAllLT0 = </xsl:text>
<xsl:if test=".<0">
<xsl:value-of select="sum(Point)" />
</xsl:if>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Thanks much for any assistance...
Jake
|