How to select following sibling/XML tag using XPath

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:

  1. The context node, against which the XPath expression is evaluated is the parent of all tr elements — not shown in your question.

  2. Each tr element has only one td with class attribute valued 'name' and only one td with class attribute valued 'desc'.

Leave a Comment