Generally A | B
is the right way to do this. But the pipe character is basically a union of two complete XPath expressions. It can be annoying to use it in a case like this:
/red/yellow/blue/green/gold | red/orange/blue/green/gold
since you're repeating the entirety of the expression except for the one small piece of it's that changing.
In cases like this, it often makes sense to use a predicate and the name()
function instead:
/red/*[name() = 'yellow' or name()='orange']/blue/green/gold
This technique gives you access to a much broader range of logical operations. It's also (conceivably) faster, as the XPath navigator only has to traverse the nodes it's testing once.