I have html like this:
<div>
<div class="a">10</div>
<div class="b">11</div>
<div class="a">20</div>
<div class="b">21</div>
</div>
Sometimes I use //div[@class="a" or @class="b"] to get four groups: [10, 11, 20, 21].
But this time I want to get something like this, two groups: ["10 11", "20 21"], could I?
I mean that how to combine two nodes(class a, class b) into one group?
This would be a working XPath 2.0 solution (running example):
//div[@class="a"]/concat(
text(),
' ',
string-join((following-sibling::div[@class="b"]/text())[1], '')
)
I don't think a solution with XPath 1.0 would be possible here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With