I have the following XML input
<a href="h1" />
<a href="h2" />
<a href="h3" />
<b id="h1">E1</b>
<b id="h2">E1</b>
<b id="h3">E2</b>
<b id="h4">E3</b>
<b id="h5">E3</b>
<b id="h6">E4</b>
<b id="h7">E5</b>
Is there a way using XSLT2/Xpath2 to get only h1 and h3 referring to the distinct values E1 and E2 and ignore h2 since it refers to the same value E1?
Thanks.
Use, assuming
aandbare children of the top element:XSLT – 2 based verification:
When this transformation is applied on the provided XML document:
the XPath expression is evaluated and the result of this evaluation is copied to the output:
Update:
As fairly noted by Michael Kay, the above solution is O(N^2) and can be slow in case there are many
bsiblings.Here is an XSLT 2.0 solution that is at least linear (or faster):
Again, when this transformation is applied on the same XML document (above), the wanted, correct result is produced: