XML:
<root></root>
XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" encoding="UTF-8"/>
<xsl:template match="/root">
absent_node EQUALS zero-length string [<xsl:value-of select="absent_node=''"/>];
absent_node NOT EQUALS zero-length string via != [<xsl:value-of select="absent_node!=''"/>]
</xsl:template>
</xsl:stylesheet>
结果:
absent_node EQUALS zero-length string [false];
absent_node NOT EQUALS zero-length string [false]
我看到了similar issue with python但这里需要解释。
如果我想在不通过 text() 或 string() 进行显式值类型转换的情况下获得恰好相反的结果,是否首选 not()?
最佳答案
这是此类比较的预期结果。
您正在将节点集与字符串进行比较。 rules对于这样的比较状态:
the comparison will be true if and only if there is a node in the node-set such that the result of performing the comparison on the string-value of the node and the other string is true.
此规则对所有比较运算符 (=, !=, <=, <, >= and >
) 统一定义。
由于您的节点集是空的,因此无论您使用哪个运算符,其中都不会有比较返回 true 的节点。
习惯上使用:
not(node = 'string')
作为以下的否定:
node = 'string'
关于xml - XSLT 等于和不等于运算符对不存在的节点返回相同的结果。这怎么可能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45732643/