Open bitparity opened 2 years ago
I don't have an answer, but this is something I would like more clarification on too.
Good question. So my 'answer' to this is
//div/div[preceding-sibling::div or following-sibling::div]
We're basically asking you to find all second-level divs with siblings (which is simple enough because they are all divs) but it's less simple to formalise that as an axis, so you're on the right track. I just use an 'or' operator within the predicate to join the two filters. As with many of these questions, there are several ways to get the right answer.
As to the general question of looking for multiple elements, you can join multiple XPath expressions with a pipe |
. E.g. say you want a list of a line group and ab elements in Bad Hamlet.
//lg | //ab
I'm going back over some of the xpath exercises from the last one, and I wanted to write an xpath for question 2.1, "Write an axis expression that finds all sibling elements of second-level divs," but that would exclude other divs.
I know
//div/div/preceding-sibling::*[name(.) != "div"]
works, but to make it proper, i need afollowing-sibling
version. How do I ask forpreceding-sibling::*
ANDfollowing-sibling::*
with my given predicate?