我有以下 XML:
<a>
<b>
<d>D1 content (can include child nodes)</d>
</b>
<b>
<c>C1 content (can include child nodes)</c>
</b>
<b>
<e>E1 content (can include child nodes)</e>
</b>
<b>
<c>C2 content (can include child nodes)</c>
</b>
</a>
使用 XSLT 1.0,我需要简单地生成:“cde”;即 /a/b/ 的直接子节点名称的不同列表,按节点名称排序。每个 b 恰好有一个任意名称的子代。
我可以生成“ccde”:
<xsl:for-each select="/a/b/*">
<xsl:sort select="name(.)"/>
<xsl:value-of select="name(.)" />
</xsl:for-each>
我尝试过使用通常的 previous-sibling:: 比较,但由于每个 b 只有一个孩子,所以前一个兄弟总是什么都没有。
首先将此关键元素添加到 XSL 的顶部:-
<xsl:key name="tagNames" match="/a/b/*" use="name()" />
现在你的 for every 循环可以如下所示:-
<xsl:template match="/*">
<xsl:for-each select="/a/b/*[count(. | key('tagNames', name())[1]) = 1]">
<xsl:sort select="name()" />
<xsl:value-of select="name()" />
</xsl:for-each>
</xsl:template>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)