Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xpath - get first 10 items of selected set

xml again..

I want to select a sub set of nodes ( for pagination purposes ) from a set.

$nodes = $xml->query(//parent
                        /child[sex = 'male' 
                               and position() >= 10 
                               and position() < 21]);

If I'm not mistaken that would only select male children who are the 10th to 20th child.

what I need is to select the first 10-20 (or 30-40) males in the set...

sure I'm being a noob and have done this before but its friday...

ta peeps

like image 924
Ian Wood Avatar asked Jan 21 '11 14:01

Ian Wood


People also ask

How do I find the first element of XPath?

Find the first element by CSS selector. Find the first element by tag name. Find the first element by partial link text. In order to get the first element of an ID or name of an element, we can use the XPath to display the first value of an element.

How do I select the first child in XPath?

The key part of this XPath is *[1] , which will select the node value of the first child of Department .

How does XPath select child elements?

For the div element with an id attribute of hero //div[@id='hero'] , these XPath expression will select elements as follows: //div[@id='hero']/* will select all of its children elements. //div[@id='hero']/img will select all of its children img elements. //div[@id='hero']//* will select all of its descendent elements.


1 Answers

Have the position condition operate on the result nodeset of your initial condition:

//parent/child[sex='male'][position() >= 10 and position() < 21]
like image 164
Chris Cameron-Mills Avatar answered Sep 20 '22 23:09

Chris Cameron-Mills