What is the XPath to select a range of nodes?

Viewed 29318

I have an XML file that's structured like this:

 <foo>
     <bar></bar>
     <bar></bar>
     ...
</foo>

I don't know how to grab a range of nodes. Could someone give me an example of an XPath expression that grabs bar nodes 100-200?

4 Answers

To select range, you must use position(), and use the clause 'and'. I'm going write two ways:

//foo//bar[position() >= 100 and position() <= 200]

or

//foo//bar[position() >= 100][position() <= 200]
Related