jamarogers 0 Posted June 18, 2013 Report Share Posted June 18, 2013 Hi All, I'm a newbie here and to xml/xslt code. I've viewed the tutorials more than once and several on Youtube, but remain a bit confused with SUM(). Here's what I've got...an xml of what I think is called a flat structure(many Point elements to one Gather element). This xml is auto generated, so not much I can do about its format. Some of the data points (Point) are +(left of a flight path), while others are -(right of a flightpath). I wish to determine an average flght path deviation and don't really care whether its right(-) or left(+). I've figured out the code to sum them all, count and divide, but that does not give a true (absolute) deviation, since the negatives are subtracted from the positives.My thoughts are to sum all - and multiply by -1, then add back to sum of all + and divide by count of ALL.Here's my code:This works and outputs a list of ALL Point elements...<xsl:for-each select="Gather/Stat/Point"><xsl:value-of select="."/><xsl:text>, </xsl:text></xsl:for-each>This works and 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>This works and lists negative values of Point...<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>Here's the problem, trying to sum negative values of Point...<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>Help PLEASE!!!Jake Quote Link to post Share on other sites
Martin Honnen 16 Posted June 19, 2013 Report Share Posted June 19, 2013 You don't need for-each at all I think, you can simply use <xsl:value-of select="sum(Gather/Stat/Point[. < 0])"/> If that does not help then show a sample of the XML you have. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.