### Email Archive: saxon-help (read-only)

 Re: [saxon] Comparing a string to an empty node.. From: Pierrick Brihaye - 2007-05-19 19:10 ```Svante Schubert a écrit : > Both result into false! I would have assumed that the negation of one > expression would result into the other, therefore unequal would be > 'true'. Then, you have missed this one in http://www.w3.org/TR/xpath20/#id-general-comparisons : > The following example contains two general comparisons, both of which > are true. This example illustrates the fact that the = and != > operators are not inverses of each other. > > (1, 2) = (2, 3) (1, 2) != (2, 3) Cheers, p.b. ```

 Re: [saxon] Comparing a string to an empty node.. From: Pierrick Brihaye - 2007-05-19 19:10 ```Svante Schubert a écrit : > Both result into false! I would have assumed that the negation of one > expression would result into the other, therefore unequal would be > 'true'. Then, you have missed this one in http://www.w3.org/TR/xpath20/#id-general-comparisons : > The following example contains two general comparisons, both of which > are true. This example illustrates the fact that the = and != > operators are not inverses of each other. > > (1, 2) = (2, 3) (1, 2) != (2, 3) Cheers, p.b. ```
 Re: [saxon] Comparing a string to an empty node.. From: Ed Davies - 2007-05-19 20:27 ```Svante Schubert wrote: > I stumbled over a strange behavior in saxonb8-9j when comparing a string > with an empty node set: > > EQUAL result into select="notexistingelmeent = 'SEARCH_STRING'"/>! > UNEQUAL result into select="notexistingelmeent != 'SEARCH_STRING'"/>! > > Both result into false! I would have assumed that the negation of one > expression would result into the other, therefore unequal would be 'true'. This is not technically a Saxon specific question as it is general to any XSLT processor, but... The left hand side of both your (in)equalities is a sequence. The comparison operators "match" any element in the sequence (they are existentially quantified) so the first would be true if there was any "notexistingelmeent" equal to 'SEARCH_STRING'. Similarly, the second would be true if there was any element in the sequence which was not equal to the string. If the sequence is empty then there is no element which is equal so the result for "=" is false and, similarly, there is no element which is different so again for != the result is false. (By the way, our illustrious leader's XPath 2.0 book describes the = operator (and the other general comparison operators) in detail starting on page 188 but doesn't reference this page under «=» in the index, where it does reference other pages discussion this operator. I sort-of knew these rules but wanted to double check.) Ed. ```
 Re: [saxon] Comparing a string to an empty node.. From: Michael Kay - 2007-05-19 22:53 ```> I would have assumed that the > negation of one expression would result into the other, > therefore unequal would be 'true'. Then you need to read the language spec (or my book). For any of the "general comparison" operators (= != < > <= >="), the expression A # B means "some \$a in A, \$b in B satisfies a # b". So if either of the operands is an empty sequence, the result is false, regardless of the operator. Michael Kay http://www.saxonica.com/ ```
 Re: [saxon] Comparing a string to an empty node.. From: Svante Schubert - 2007-05-20 11:03 ```Hi Ed, Ed Davies wrote: > Svante Schubert wrote: > >> I stumbled over a strange behavior in saxonb8-9j when comparing a string >> with an empty node set: >> >> EQUAL result into > select="notexistingelmeent = 'SEARCH_STRING'"/>! >> UNEQUAL result into > select="notexistingelmeent != 'SEARCH_STRING'"/>! >> >> Both result into false! I would have assumed that the negation of one >> expression would result into the other, therefore unequal would be 'true'. >> > > This is not technically a Saxon specific question as it is > general to any XSLT processor, but... > > The left hand side of both your (in)equalities is a sequence. > The comparison operators "match" any element in the sequence > (they are existentially quantified) so the first would be true > if there was any "notexistingelmeent" equal to 'SEARCH_STRING'. > Similarly, the second would be true if there was any element in > the sequence which was not equal to the string. > > If the sequence is empty then there is no element which is > equal so the result for "=" is false and, similarly, there > is no element which is different so again for != the result > is false. > You are right, it was obviously a wrong assumption that boolean algebra could be used upon the comparison operators. The general comparisons equal and unequal are not inverses of each other (and not transitive for themselves). http://www.w3.org/TR/xpath20/#id-general-comparisons Thanks for your help Ed! > > (By the way, our illustrious leader's XPath 2.0 book describes > the = operator (and the other general comparison operators) in > detail starting on page 188 but doesn't reference this page > under «=» in the index, where it does reference other pages > discussion this operator. I sort-of knew these rules but > wanted to double check.) > > Ed. ```