Here is an excerpt of my xml :
content
Simpler than the accepted answer:
//node[@id='1']/following-sibling::node[following::node[@id='2']]
node
elementsnode
with id="2"
somewhere after them.Shown in action with a more clear test document (and legal id
values):
xml = '
content
content
'
# A Ruby library that uses libxml2; http://nokogiri.org
require 'nokogiri'; doc = Nokogiri::XML(xml)
expression = "//node[@id='c']/following-sibling::node[following::node[@id='g']]"
puts doc.xpath(expression)
#=>
#=>
#=>