Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to find all not matching elements in XPath expression of XSL template?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading