I’m trying to select elements (a) with XPath 1.0 (or possibly could be with Regex) that are following siblings of particular element (b) but only preceed another b element.
<img><b>First</b><br>
<img> <a href="/first-href">First Href</a> - 19:30<br>
<img><b>Second</b><br>
<img> <a href="/second-href">Second Href</a> - 19:30<br>
<img> <a href="/third-href">Third Href</a> - 19:30<br>
I tried to make the sample as close to real world as possible. So in this scenario when I’m at element
<b>First</b>
I need to select
<a href="/first-href">First Href</a>
and when I’m at
<b>Second</b>
I need to select
<a href="/second-href">Second Href</a>
<a href="/third-href">Third Href</a>
Any idea how to achieve that? Thank you!
Dynamically create this XPath:
where ‘xxxx’ is the replaced with the text of the current
<b>.This is assuming that all the elements actually are siblings. If they are not, you can try to work with the
precedingandfollowingaxes, or you write a more specific XPath that better resembles document structure.In XSLT you could also use: