xml - XSLT 删除同名节点中的节点
问题描述
我有一个 XML 文档。
它para
在其他节点中有大量para
节点。
我想删除里面的那些并保持内部文本将它连接到其他para
节点的内部文本。
示例 XML
<document>
<head>
<front>The front page</front>
</head>
<h1>
<para id="1234">This is the inner text <para> it needs joining together</para> maybe with other text</para>
</h1>
</document>
期望的输出
<document>
<head>
<front>The front page</front>
</head>
<h1>
<para id='1234'>This is the inner text it needs joining together maybe with other text</para>
</h1>
</document>
解决方案
这是相当微不足道的:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="para/para">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>