请考虑以下示例:
XML :
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="03-01.xsl"?>
<ancient_wonders>
<wonder myattribute = "Green">
<name language="English">Colossus of Rhodes1</name>
</wonder>
<wonder myattribute = "Red">
<name language="English">Colossus of Rhode2s</name>
</wonder>
</ancient_wonders>XSL :
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<!-- Output Method -->
<xsl:output method="html"/>
<!-- Root Template -->
<xsl:template match="/">
<html>
<body>
<p>Output 1 </p>
<xsl:for-each select="//name//*">
<xsl:value-of select = "."/>
</xsl:for-each>
<p>Output 2</p>
<xsl:for-each select="//name/@*">
<xsl:value-of select = "."/>
</xsl:for-each>
<p>Output 3</p>
<xsl:for-each select="//name/*">
<xsl:value-of select = "."/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>(您可以看到输出这里 )
现在,我们看到name有属性language,在本例中,language节点是name节点的子节点吗?如果是,为什么我不能在输出中看到(链接以上)?
发布于 2019-03-15 13:19:09
表达式elem/*是以下的缩写:
elem/child::*它选择所有子元素 of elem。为什么只有元素?因为:
对于主节点类型的任何节点,节点测试*都是正确的。
以及:
如果轴可以包含元素,则主节点类型为元素;
https://www.w3.org/TR/1999/REC-xpath-19991116/#node-tests
属性仅在attribute轴上可用,而在子轴上是不可用的:
每个元素节点都有一组相关的属性节点;元素是每个属性节点的父节点;然而,属性节点不是其父元素的子元素。 (强调后加)
https://www.w3.org/TR/1999/REC-xpath-19991116/#attribute-nodes
因此,在属性轴上,主要节点类型是属性,因此:
elem/attribute::*(可以缩短为elem/@*)选择elem的所有属性。
https://stackoverflow.com/questions/55183124
复制相似问题