tags:

views:

1074

answers:

3

I need to calculate the modulus of a number in XPath, but this won't work:

<xsl:if test="(count()%8)">

How would I do it? Looked at the XPath function reference here, but didn't see anything like that.

THANKS FOR THE PROMPT ANSWERS!

+10  A: 

try "mod"

see http://www.w3.org/TR/xpath#numbers

bstoney
+2  A: 

Try

<xsl:if test="(count() mod 8)">

as in XSL you have to use "mod" to get modulus

Bhushan
+1  A: 

Also watch out when doing addition/subtraction. When doing addition all should be good with $var1+$var2. But in Subtraction, since a dash (-) is valid in a variable name $var1-$var2 does not work. But $var1 - $var2 should, and number($var1) - number($var2) always should work and you can see an article I wrote about in relation to the use of XPATH in Novell's Identity Manager product.

XPATH Math thoughts

geoffc