I am dealing with some irregularities in my documents, mainly, certain nodes are present and some other times, it's not there. I want an xpath which is able to take account both situations.
For example across my documents, there are cases when span is present and when it's not there.
How can I express an xpath which will match both cases above ?
// selector will search arbitrarily deep. This will work with or without the span (it will also find divs inside of other tags besides body and span):
You can join two result-sets together using the union
/html/body/span/div/table/tr/td/a | /html/body/div/table/tr/td/a
You could use use some crazy filtering to try to do it all in one path. Untested:
/html/body/descendant-or-self::*[self::body or self::span/parent::body]/div/table/tr/td/a