This is my XML:
<f>
<a>10</a>
<a>2</a>
<a>4</a>
<a>13</a>
<b>55</b>
<b>4</b>
</f>
I'm trying to match elements <b/>
which are not equal to <a/>
:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="b[. != //a]">
<xsl:text>found!</xsl:text>
</xsl:template>
</xsl:stylesheet>
However, it doesn't work. I believe, my expression . != //a
is wrong, since //a
matches only the first occurrence of <a/>
. What is the right expression?
It's a test sample, please don't suggest other possible ways of solving this task. I only need a fix to the XPath expression.
CodePudding user response:
Most XPath users using e.g. . != $sequence
want rather not(. = $sequence)
e.g. not(. = //a)
i.e. the current .
item is not equal to any a
element.