This is akin to this question but I couldn't get the suggested sumAll function to work. I also have several different columns to sum and it just seems silly to have a separate template for each column I want to sum. I have a column where not all rows have a value. I want to sum the rows that do have values. I have tried the following:

<xsl:value-of select="sum($nodeset/@MyField[string-length(@MyField) &gt; 0])" />

This seems like it should work. However, I get 0 as the total. The very same data view shows individual rows below the total with values like 300, 160, etc., so 0 is obviously an incorrect total. I have tried wrapping @MyField in number(), but I end up getting NaN as the total then. All the examples I've seen online talk about translate() and dealing with British-style decimals, but I'm working with American-style decimals and I don't see any individual values with commas.

How can I sum this column?

1 Answer 1


I'm not positive that this will answer your entire question as I'm not certain about your use of decimals etc.

Try replacing the string-length(@MyField) with string-length(.) :

<xsl:value-of select="sum($nodeset/@MyField[string-length(.) &gt; 0])" />

I've tested this quickly and this returns a value where your expression returned 0, so it should go a long way to solving your problems.

  • That got it! I'd vote you up but I don't have the reputation for it. :( Commented Nov 4, 2010 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.