Re: [xsl] Is "A != B" equivalent to "not(A = B)"?

Subject: Re: [xsl] Is "A != B" equivalent to "not(A = B)"?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Sat, 27 Apr 2002 10:16:14 +0100
Hi Michael,

> I've got a stylesheet that produces different results depending on
> whether I use "A != B" or "not(A = B)"? Is this supposed to happen?
> Can someone explain why? It's not very intuitive.

The reason for the difference lies in how comparisons between node
sets work in XSLT. Whenever you compare two node sets, the comparison
returns true if the comparison would be true for any similar
comparisons on the individual nodes in that node set.

Expanding the comparison (using a slightly adapted form of XPath 2.0
syntax) makes this easier to understand: A != B is equivalent to:

  some $a in A, $b in B satisfies $a != $b

This returns true when there is any combination of $a and $b that
aren't equal; the only time this isn't the case is if all the $as in A
are equal and all the $bs in B are equal, and they're all equal to
each other.

On the other hand not(A = B) is equivalent to:

  not(some $a in A, $b in B satisfies $a = $b)

This returns true when there isn't any combination of $a and $b that
are equal. This is generally what you want.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread