Subject: Re: [xsl] Understanding Identity Transformations From: Dimitre Novatchev <dnovatchev@xxxxxxxxx> Date: Sun, 13 Feb 2005 10:33:56 +1100 |
What Mike is explaining here is something crucial. Not understanding the difference in the behaviour on node-sets of the "!="operator and the not() function causes enormous confusion to a lots of XSLT programmers. One of the most valuable advice from even the first edition of "XSLT Programmer's Reference" is always to try to use "not()" and to use "!=" only when it is really necessary. Cheers, Dimitre Novatchev On Sat, 12 Feb 2005 22:00:49 -0000, Michael Kay <mike@xxxxxxxxxxxx> wrote: > > > Wow.. that is easy except that I do not understand your notice > > > explanation... the difference between your not( ... ) and your !=. > > > > "@cat != 'BLUE'": will be true if the context node has a > > 'cat' attribute > > *and* if it has a 'cat' attribute not equal to 'BLUE'. So > > it's the same as > > "boolean(@cat) and not(@cat='BLUE')" > > > > "not(@cat='BLUE')": will be true if the context node has no 'cat' > > attribute *or* if it has a 'cat' attribute not equal to > > 'BLUE'. So it's > > equal to "not(@cat) or not(@cat='BLUE')" > > Let's try to phrase it a different way. An expression such as X=Y in XPath > is shorthand for > > some $x in X, $y in Y satisfies $x=$y > > in other words, it's true if there's some pair of values from the two sets > that are equal. > > Similarly, X!=Y is short for > > some $x in X, $y in Y satisfies $x!=$y > > which is true if there's some pair that are not equal. > > This means that if X is an empty set, then X=3 and X!=3 must both be false. > If you're testing an attribute, @A=3, then @A is a set that's either empty > or contains one node. If there's no A attribute, then @A!=3 is false > (because there's no A that's not equal to 3), but not(@A=3) is true (because > it's not true that there's an A that's equal to 3). > > Michael Kay > http://www.saxonica.com/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Understanding Identity Tr, Karl Stubsjoen | Thread | Re: [xsl] Understanding Identity Tr, Joris Gillis |
[xsl] XSL create XML files, Marcos Hercules dos | Date | RE: [xsl] XSL create XML files, Michael Kay |
Month |