我如何使用 Xsl 找到所有节点的名称与其他节点的值相似 像这样:
<root>
<data1>
<subdata1>
...
<selectThese></selectThese>
...
</subdata1>
</data1>
<nodesetFind>
<node1>selectThese</node1>
</nodesetFind>
</root>
结果:<selectThese></selectThese>
最佳答案
使用:
/*/data1//*[name() = /*/nodesetFind/*]
在 XSLT 转换中展示:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:copy-of select="/*/data1//*[name() = /*/nodesetFind/*]"/>
</xsl:template>
</xsl:stylesheet>
当此转换应用于提供的 XML 文档时:
<root>
<data1>
<subdata1>
...
<selectThese></selectThese>
...
</subdata1>
</data1>
<nodesetFind>
<node1>selectThese</node1>
</nodesetFind>
</root>
产生了想要的、正确的结果:
<selectThese></selectThese>
关于xml - Xsl 查找所有节点,然后将其命名为其他节点的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3609215/