Excluding values from XSL Sum.
Posted on 2011-03-02
What I am doing: I am attempting to sum values.
The problem: The XML file includes characters that cannot be summed. I am unable to edit the XML data file. I need to locate a method to exclude values that match a certain character and sum the remaining values. (eg. 22+ 9 + '-' + 5) Obviously the '-' causes the XSL sum function to return "NaN"
I am still relatively new to XSL and will freely admit that I conceptually know how do to this, and in an OOP way I know what to do, but I do not know the syntax or language of XSL well enough to achieve the required functionality.
While this is not a "for-each" there is only one key (<key>0..10</key> is a sibling of NodeG which is Value) and value pair per occurrence of NodeB.
The above summation correctly sums values if there are no random non numeric characters. The below XML example contains two "Values"; 29 and -. Currently when running the above sum I get "NaN". I would like to exclude the '-' and get 29.
In attempting to do some research it appears that I might be able to use the "translate(str, str, str) function, but am not sure how this can be incorporated into the sum function.
Example XML structure: