Why do you say
(a/b)[position() <= 4] should work, but seems it's xpath 2.0
? That's perfectly legitimate XPath 1.0, and in fact is a common idiom for this purpose. I just tested it to confirm that it's accepted and works correctly.
It may also be more efficient than using count(preceding::b)
, depending on the XPath processor.