What is the difference between the not()
operator and !=
?
See this example:
<?xml version="1.0" encoding="UTF-8"?>
<body>
<test>123</test>
</body>
<xsl:template match="/">
<xsl:if test = "/body/test = (123, 2)">true1</xsl:if>
<xsl:if test = "not(/body/test != (123, 2))">true2</xsl:if>
</xsl:template>
http://xsltransform.net/jyH9rMx
Why do i get true1
as a result, but not true2
? I would expect the two lines to be equivalent. Why are they not?
In Python != is defined as not equal to operator. It returns true if operands on either side are not eual to each other, and returns false if they are equal.
It means “Strictly Not Equal” and returns true where strict equality would return false and vice versa. Strict inequality will not convert data types. For example 1 !== '1' will return true since 1 is an integer and '1' is a character and no data type conversion take place.
Here is the answer – Technically there is no difference between != and <>. Both of them work the same way and there is absolutely no difference in terms of performance or result. Here is the follow up question I received right I answer that there is no difference between those operator.
The = is a simple assignment operator. It assigns values from right side operands to the left side operand. While on the other hand == checks if the values of two operands are equal or not. If yes, the condition becomes true and it returns a non zero value.
To answer the question/s you didn't ask, but should have:
"123 = (123, 2)"
returns true because 123 is equal to 123.
"not(123 = (123, 2))"
returns false because as shown above, the inner expression is true - and the outer not() merely reverses it.
"123 != (123, 2)"
returns true, because 123 is not-equal to 2.
"not(123 != (123, 2))"
returns false because as shown above, the inner expression is true, and the outer not() merely reverses it.
For reference, see: http://www.w3.org/TR/xpath20/#id-value-comparisons
The key thing to realise with the "general" comparison operators in XPath (including =
and !=
) is that they are implicitly existentially quantified over their argument sequences. The expression X = Y
means the same as the explicitly quantified expression
some $x in X, $y in Y satisfies $x eq $y
(eq
being the single item equality operator). So not(X = Y)
means
not(some $x in X, $y in Y satisfies $x eq $y)
which is equivalent to saying
every $x in X, $y in Y satisfies $x ne $y
Conversely X != Y
means
some $x in X, $y in Y satisfies $x ne $y
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With