Totaling/Summing string values
After further research on VelocityReviews I found the following solution.
I used a for-each loop to set the value of a xslt variable (ie: DeclaredValues) to a temporary tree whose elements contain the values to sum after stripping off the currency code with a substring-before function.
I initialized the temporary tree element => TempDeclaredValue = 0 so I never have an empty node.
<xsl:variable name="DeclaredValues">
<TempDeclaredValue>0</TempDeclaredValue>
<xsl:for-each select="Release/ReleaseRefnum[ReleaseRefnumQualifierGid/Gid/Xid='NET PRICE']/ReleaseRefnumValue">
<TempDeclaredValue>
<xsl:value-of select="substring-before(../ReleaseRefnumValue,' ')"/>
</TempDeclaredValue>
</xsl:for-each>
</xsl:variable>
After iterating through all of the NET PRICE reference num elements, I then just execute a sum() function on the variable => DeclaredValues. The only caveat was that I had to include the namespace/extension library => xmlns:exslt="http://exslt.org/common" and use exslt:node-set() so I could sum the nodes correctly because I was getting the error
{"To use a result tree fragment in a path expression, first convert it to a node-set using the msxsl:node-set() function."}
<TotalDeclaredValue>
<xsl:value-of select="sum(exslt:node-set($DeclaredValues)/*)"/>
</TotalDeclaredValue>
Hope this helps others that are having a similiar issue.
Last edited by bsparker; July 20th, 2011 at 05:44 PM..
Reason: hit enter key by accident before completing
|