gpt4 book ai didi

xslt - exsl :node-set treat as the root node? 是什么

转载 作者:行者123 更新时间:2023-12-05 00:54:51 26 4
gpt4 key购买 nike

我无法理解 exsl:node-set 函数的工作原理。

我有一些 XML,我正在扩展并使用它来动态填充 exsl:node-set。假设它目前采用这种格式:

<xsl:variable name="wrap">
<nodes>
<node/>
<node/>
<node/>
</nodes>
</xsl:variable>
<xsl:variable name="wrapNodeSet" select="exsl:node-set($wrap)"/>

这按要求工作并且输出 $wrapNodeSet 显示上面的节点标记。根节点名称使用名称 ($wrapNodeSet/*) 显示为“节点”。

现在我需要将其扩展为具有 2 个节点并动态填充节点集。所以:

    <xsl:variable name="wrap">
<nodes tier="a">
<node/>
<node/>
<node/>
</nodes>
<nodes tier="b">
<node/>
<node/>
<node/>
</nodes>
</xsl:variable>
<xsl:variable name="wrapNodeSet" select="exsl:node-set($wrap)/nodes[@tier='b']"/>

输出节点集包括节点元素,但输出根节点的名称现在更改为“节点”。

有人可以解释为什么节点元素仍然输出吗?

最佳答案

<xsl:variable name="wrapNodeSet" 
select="exsl:node-set($wrap)/nodes[@tier='b']"/>

这从使用 node-set() 扩展获得的树中选择任何 nodes 元素,(nodes 元素)有一个tier 属性值为 'b'

然后:

name($wrapNodeSet/*)

生成包含在 $wrapNodeSet 中的第一个节点的第一个子元素的名称。由于 $wrapNodeSet 只包含一个 nodes 元素,而 nodes 元素只有 node 子元素,第一个这样的子元素是一个 node 元素及其名称,因为任何 node 元素的名称都是 "node"

为什么您会在此结果中看到任何意外?

换句话说:

ext:node-set()$wrap 上的应用在这两种情况下都会产生相同的树,但在第二种情况下,您使用不同的、更长的 XPath ext:node-set($wrap) 结果的表达式——因此您从这两个不同的 XPath 表达式的计算中得到不同的结果。

关于xslt - exsl :node-set treat as the root node? 是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11291505/

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