首页 > 解决方案 > 如何使用 XSL 从父节点复制所有子节点

问题描述

以下是我的输入:

<csv>
<row>
    <stuff>a</stuff>
    <more>1</more>
    <evenmore>123</evenmore>
    <roww>
        <other>1345</other>
       <other>13845</other>
    </roww>
</row>
</csv>

预期输出:

 <roww>
        <other>1345</other>
       <other>13845</other>
    </roww>

谁能让我知道如何使用 XSL 做到这一点?

标签: xsltxslt-1.0xls

解决方案


好吧,这只是为了匹配父节点并执行copy-of.

<xsl:copy-of>元素创建当前节点的副本。

注意:命名空间节点、子节点和当前节点的属性也会自动复制!

实现预期输出的XSLT 1.0解决方案可以是:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes" />

<xsl:template match="/csv">
    <xsl:copy-of select="row/roww" />
</xsl:template>

</xsl:stylesheet>

https://xsltfiddle.liberty-development.net/bFN1y93


推荐阅读