For example:
<a>
<b>
<c1>c1 text</b1>
<c2 c2attr="10">c2 text</b2>
<c3>c3 text</b3>
</b>
<b>
<c1>c1 text</b1>
<c2 c2attr="5">c2 text</b2>
<c3>c3 text</b3>
</b>
</a>
I want to select the <b> element which has a <c2> child with the maximum c2attr attribute; in this example, the first one (10 > 5).
I have tried
/a/b[not(c2@c2attr <= preceding-sibling::c2@c2attr) and not(c2@c2attr <=following-sibling::c2@c2attr)]
But PHP says that it’s invalid…
You’re missing slashes before the
@signs, and you need to look forpreceding-siblingelements namedb, notc2:However this kind of check will be quadratic in the number of
belements, as it’s comparing everybwith every otherb. It would be more efficient to simply extract all thebelements, then iterate over them (once) using PHP code, keeping track of the highestc2attrvalue you’ve seen so far and whichbthat belongs to. This would be linear rather than quadratic.