How to select following sibling/XML tag using XPath
Solution 1:
How would I accomplish the nextsibling and is there an easier way of doing this?
You may use:
tr/td[@class='name']/following-sibling::td
but I'd rather use directly:
tr[td[@class='name'] ='Brand']/td[@class='desc']
This assumes that:
The context node, against which the XPath expression is evaluated is the parent of all
tr
elements -- not shown in your question.Each
tr
element has only onetd
withclass
attribute valued'name'
and only onetd
withclass
attribute valued'desc'
.
Solution 2:
Try the following-sibling
axis (following-sibling::td
).
Solution 3:
For completeness - adding to accepted answer above - in case you are interested in any sibling regardless of the element type you can use variation:
following-sibling::*