0
votes

This is my HTML data

<book></book>
<book></book>
<book></book
....
....
'N' books

I'd like to get all the text data between all the <book></book> nodes except the last 2 <book> nodes

Basically i need //book[1 to n-2]//text()

Is there an XPATH query i can write for this?

1
Try something like //book[1 <= position() && position() <= count(.)-2]//text() (I did not try it out though...) - Matthias J. Sax

1 Answers

1
votes

One possible way to get all book elements within the same parent, except the last two book elements (in other words, excluding the last and one before the last) :

//book[position() < last()-1]