删除特定元素的命名空间 [英] remove namespace for a particular element
本文介绍了删除特定元素的命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法删除特定元素的命名空间?
Is there any way to remove namespace for a particular element?
推荐答案
这种转变:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:x="my:x">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="x:*">
<xsl:element name="{local-name()}">
<xsl:copy-of select="namespace::*[not(. = namespace-uri(..))]"/>
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
从 "my:x"
命名空间中删除任何元素并将其放入无命名空间"中.
removes any element from the "my:x"
namespace and puts it into "no namespace".
例如,当应用于以下 XML 文档时:
For example, when applied to the following XML document:
<t>
<x:a xmlns:x="my:x"/>
</t>
产生想要的、正确的结果:
<t>
<a/>
</t>
要仅从特定命名空间中删除特定元素,必须使覆盖标识规则的模板更加具体以仅匹配所需元素.
这篇关于删除特定元素的命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文