Xalan特定条件下混淆属性与命名空间节点的疑似Bug确认问询
Xalan 1.12.0 中 attribute::node() 误将命名空间节点识别为属性节点的Bug确认
环境信息
- 系统:Ubuntu 22.04
- Xalan版本:1.12.0
- Xerces版本:3.2.3
最小复现示例
test.xml
<root/>
sheet.xsl
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes"/> <xsl:template match="root"><xsl:value-of select="count(attribute::node())"/></xsl:template> </xsl:stylesheet>
执行命令
xalan -xsl sheet.xsl -in test.xml
问题现象
预期输出为0(因为<root/>节点没有任何属性节点),但实际输出是1。
进一步验证不同表达式的结果:
- 替换为
name(attribute::node()),输出为xml - 替换为
attribute::node(),输出为http://www.w3.org/XML/1998/namespace
这说明Xalan错误地将默认的xml命名空间节点当作属性节点返回了。
特殊情况说明
该Bug仅在使用完整的attribute::node()表达式时触发,以下表达式均能正确返回无属性节点的结果:
attribute::*@*attribute::xml@xml
结论
这确实是Xalan的一个Bug,违反了XPath 1.0规范——命名空间节点和属性节点属于两类不同的节点,attribute::轴不应包含命名空间节点。
内容的提问来源于stack exchange,提问作者Peter
相关产品推荐
相关产品推荐

