How can I select the second last item in a xpath query?

xpath

Solution

You can use `last()` which represents the last item in the context:

/bookstore/book[position()>=2 and position() <= (last() - 1)]

Problem

I'm new to xpath and I understand how to get a range of values in xpath: ``` /bookstore/book[position()>=2 and position()<=10] ``` but in my case, I need to get above 2 and one less then the total(so if there's 10 then I need 9, or if there's 5, I need up to the 4th spot). I'm applying my code to different pages and the number of entries is not always the same. In python, I could do something like book[2:-2], but I'm unsure if I can do this within xpath.

Original source