这个问题在这里已经有了答案:
How can I prevent these redundant namespaces from an XSLT stylesheet?
(2 个回答)
8 年前关闭。
我正在尝试使用 <xsl:copy-of select="." />
复制当前节点下存在的所有节点它也在复制根节点中存在的命名空间。
如何避免这种情况?
最佳答案
如果 namespace 不需要,那么在 XSLT 2.0 中您可以使用 <xsl:copy-of select="." copy-namespaces="no"/>
.但是请注意,这只会删除未使用的命名空间节点;它不会改变任何元素或属性的命名空间。如果您希望副本中的元素或属性位于与原始名称不同的命名空间中,那么您需要执行递归浅拷贝,如下所示:
<xsl:template match="*">
<xsl:element name="{local-name()}" namespace="new-namespace">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
关于xml - <xsl :copy-of copying the namespace present in the root node . 如何避免这种情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19374011/