A subtlety.  Here's a quote from Kay's XSLT book (the section that describes EqualityExpr):
 
<quote>
You can't assume that <$X!=3> means the same as <not($X=3)>.  When <$X> is a node-set, the first expression is true if any node in the node-set is not equal to 3, while the second is true if no node in the node-set is equal to 3.
</quote>
 
Your $LastDir is a node-set, so that is why you are getting different results.
 
PC2
-----Original Message-----
From: Mark Neves [mailto:Mark.Neves@Xitec-Software.com]
Sent: September 27, 2001 07:49
To: saxon-help@lists.sourceforge.net
Subject: [saxon] When "not($Var=@att)" differs from "$Var!=@att"

Hi,

It appears that the following two statements are not always the same:
        <xsl:if test="not($LastDir=@direction)">
        <xsl:if test="$LastDir!=@direction">

Attached are 3 files that illustrate the problem, test.xml, test.xsl (which works), and test2.xsl (which doesn't work)

test.xsl contains:
        <xsl:template match="KEY">
                <xsl:variable name="LastDir" select="preceding-sibling::KEY/@direction"/>
                <xsl:if test="not($LastDir=@direction)">
                        <xsl:value-of select="concat(' ',@direction,' KEY')"/>
                </xsl:if>
                <xsl:value-of select="concat(' ',@name)"/>
        </xsl:template>

test.xml contains:
        <doc>
                <keys>
                        <KEY direction="ASCENDING" name="AK1"/>
                        <KEY direction="ASCENDING" name="AK2"/>
                        <KEY direction="DESCENDING" name="DK1"/>
                </keys>
        </doc>

Using Instant Saxon, the command "saxon test.xml test.xsl" gives:
         ASCENDING KEY AK1 AK2 DESCENDING KEY DK1

which is correct.  The clause "not($LastDir=@direction)" successfully detects that when LastDir is empty, it is not equal to the value of the current node's "direction" attribute.

However, using test2.xsl, which contains the line <xsl:if test="$LastDir!=@direction"> gives
         AK1 AK2 DESCENDING KEY DK1

i.e. when LastDir is empty, "$LastDir!=@direction" equates to False

I've tried Saxon versions 6.2.2, 6.4.3 and 6.4.4, and they all behave the same way.

Is this a bug, or is there a subtlety I'm unaware of?

Regards,
Markn.

<<test.xml>> <<test.xsl>> <<test2.xsl>>