2
XML:XSLT等于和不等于运算符为缺少节点返回相同的结果。这怎么可能?
<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()首选?
引证距离的XPath 1.0规范,但2.0规则基本上是相同的,虽然推广到任意序列。当X是一个空序列时,则(X ='a')表示“X中有一个等于'a'的项目”,而(X!='a')表示“X中有一个项目不等于'a'“;如果X是空序列,则两个条件都是假的。 –
顺便提一句,请注意,如果您在SQL中将缺失的元素/属性视为null,那么语义与SQL语义非常相似:当在谓词中使用X ='a'和X!='a'时,都会导致X不被选中。不同的是,在SQL中,谓词有效地评估为null,而在XPath中,它评估为false。 –