您的代码:
<h1><xsl:value-of select="h1"/></h1>
父母亲
标签(包含
h1
h1
,以防止原件的复制
标识模板中的元素。
请看以下脚本:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*"/>
<xsl:template match="main">
<xsl:copy>
<h1><xsl:value-of select="h1"/></h1>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="h1"/>
<xsl:template match="@*|node()">
<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>
</xsl:transform>
<main>
<h1>aaa</h1>
<h1>bbb</h1>
<h1>ccc</h1>
<h2>xxx</h2>
</main>
<main>
<h1>aaa bbb ccc</h1>
<h2>xxx</h2>
</main>