gpt4 book ai didi

xml - 属性节点是元素节点的子节点

转载 作者:数据小太阳 更新时间:2023-10-29 02:55:42 28 4
gpt4 key购买 nike

考虑以下示例:

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>

(可以看到输出 here )

现在,我们看到 name 有属性 language现在在这种情况下,language 节点是 name 节点的子节点吗?如果是,为什么我无法在输出(上面的链接)中看到它?

最佳答案

表达式 elem/* 是以下内容的缩写:

elem/child::*

选择 elem 的所有子元素。为什么只有元素?因为:

A node test * is true for any node of the principal node type.

和:

If an axis can contain elements, then the principal node type is element;

https://www.w3.org/TR/1999/REC-xpath-19991116/#node-tests


属性仅在 attribute 轴上可用,从不在子轴上可用:

Each element node has an associated set of attribute nodes; the element is the parent of each of these attribute nodes; however, an attribute node is not a child of its parent element.
(emphasis added)

https://www.w3.org/TR/1999/REC-xpath-19991116/#attribute-nodes


在属性轴上,主要节点类型是属性,因此:

elem/attribute::*

(可简写为elem/@*)选择elem的所有属性。

关于xml - 属性节点是元素节点的子节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55183124/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com