Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between != and not ( = )

Tags:

xml

xslt

xslt-2.0

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?

like image 762
Willi Fischer Avatar asked Mar 25 '15 16:03

Willi Fischer


People also ask

What is meaning of != In Python?

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.

What is difference between !== and !=?

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.

What is difference between <> and NOT operators?

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.

What is the difference between != and == in Python?

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.


2 Answers

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

like image 50
michael.hor257k Avatar answered Oct 02 '22 14:10

michael.hor257k


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
like image 34
Ian Roberts Avatar answered Oct 02 '22 16:10

Ian Roberts