这是一个简单的 XSLT 1.0 兼容解决方案:
样式表
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- Identity transform -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- Keep only the first <node> element -->
<xsl:template match="node[1]">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
<!-- Apply all repeatable_node children of following <node> siblings. -->
<xsl:apply-templates select="following-sibling::node/repeatable_node"/>
</xsl:copy>
</xsl:template>
<!-- Drop all <node> elements following the first <node> element -->
<xsl:template match="node[position() > 1]"/>
</xsl:stylesheet>
输入
<nodes>
<node>
<sub_node_1> value_1 </sub_node_1>
<sub_node_n> value_n </sub_node_n>
<repeatable_node> another_value_1 </repeatable_node>
</node>
<node>
<sub_node_1> value_1 </sub_node_1>
<sub_node_n> value_n </sub_node_n>
<repeatable_node> another_value_m </repeatable_node>
</node>
</nodes>
输出
<?xml version="1.0"?>
<nodes>
<node>
<sub_node_1> value_1 </sub_node_1>
<sub_node_n> value_n </sub_node_n>
<repeatable_node> another_value_1 </repeatable_node>
<repeatable_node> another_value_m </repeatable_node>
</node>
</nodes>