XSLT - 删除多个节点并添加新节点
XSLT - remove multiple nodes and add new node
这可能是一个简单的 xslt 问题。我有 xml 如下,
<doc>
<chap>
<p>This is a para</p>
</chap>
</doc>
我需要的是删除 <doc>
和 <chap>
节点并将节点添加到结果三。
所以输出应该是,
<new>
<p>This is a para</p>
</new>
当我写一个模板到
<xsl:template match="doc">
<new><xsl:apply templates/></new>
</template>
它将 <chap>
添加到结果树。
当我写模板到<chap>
<xsl:template match="chap">
<new><xsl:apply templates/></new>
</template>
它将 <doc>
添加到结果树。
而且我无法抑制 <xsl:template match="chap"/>
之类的任何元素。因为它也删除了子节点。
如何使用 xsl 获得所需的输出?
使用<xsl:template match="doc"><xsl:apply-templates/><xsl:template>
,然后您就可以使用您的
<xsl:template match="chap">
<new><xsl:apply templates/></new>
</template>
连同身份转换模板,您可能也有(尽管您没有展示)。
这可能是一个简单的 xslt 问题。我有 xml 如下,
<doc>
<chap>
<p>This is a para</p>
</chap>
</doc>
我需要的是删除 <doc>
和 <chap>
节点并将节点添加到结果三。
所以输出应该是,
<new>
<p>This is a para</p>
</new>
当我写一个模板到
<xsl:template match="doc">
<new><xsl:apply templates/></new>
</template>
它将 <chap>
添加到结果树。
当我写模板到<chap>
<xsl:template match="chap">
<new><xsl:apply templates/></new>
</template>
它将 <doc>
添加到结果树。
而且我无法抑制 <xsl:template match="chap"/>
之类的任何元素。因为它也删除了子节点。
如何使用 xsl 获得所需的输出?
使用<xsl:template match="doc"><xsl:apply-templates/><xsl:template>
,然后您就可以使用您的
<xsl:template match="chap">
<new><xsl:apply templates/></new>
</template>
连同身份转换模板,您可能也有(尽管您没有展示)。