XPath axis, get all following nodes until
Use: (//h2[. = ‘Foo bar’])[1]/following-sibling::p [1 = count(preceding-sibling::h2[1] | (//h2[. = ‘Foo bar’])[1])] In case it is guaranteed that every h2 has a distinct value, this may be simplified to: //h2[. = ‘Foo bar’]/following-sibling::p [1 = count(preceding-sibling::h2[1] | ../h2[. = ‘Foo bar’])] This means: Select all p elements that are following siblings of the h2 … Read more