문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top