问题描述
not()
运算符和 !=
有什么区别?
What is the difference between the not()
operator and !=
?
看这个例子:
<?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
为什么我得到 true1
而不是 true2
?我希望这两行是等效的.为什么不是?
Why do i get true1
as a result, but not true2
? I would expect the two lines to be equivalent. Why are they not?
推荐答案
要回答您没有提出但应该提出的问题:
To answer the question/s you didn't ask, but should have:
"123 = (123, 2)"
返回真,因为 123 等于 123.
returns true because 123 is equal to 123.
"not(123 = (123, 2))"
返回 false 因为如上所示,内部表达式为 true - 而外部 not() 只是将其反转.
returns false because as shown above, the inner expression is true - and the outer not() merely reverses it.
"123 != (123, 2)"
返回真,因为 123 不等于 2.
returns true, because 123 is not-equal to 2.
"not(123 != (123, 2))"
返回false,因为如上所示,内部表达式为true,而外部not() 只是将其反转.
returns false because as shown above, the inner expression is true, and the outer not() merely reverses it.
参考:http://www.w3.org/TR/xpath20/#id-value-比较
这篇关于!= 和 not ( = ) 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!