How To Create Custom XPath Functions

Posted by Agung Pambudi in ,
use 'mod' function in xpath

I am trying to select a list of elements through the following xpath: div[position() mod 2 = 1] and its not working!! But I am able to select the elements using div[position() = 1] or div[position() > 1]. Please help as I need to select elements from position "n" (even or odd).

In VWR, 'mod' operator doesn't work within the xpah .

You could write a custom xpath function instead of this , e.g, c# code :

public static bool isOdd(int pos)
if (pos % 2 == 1)
return true;

return false;

then you check the current position is as odd or even number , e.g,


@node-position : Returns the position of the current node within its parent.

No comments:

Post a Comment