How To Create Custom XPath Functions

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,

//TR[isOdd(@node-position)]/TD/A


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

About Agung Pambudi

I am a Blogger with passion in business.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment