删除特定元素的命名空间

Mad*_* CM 3 xslt

有没有办法删除特定元素的命名空间?

Dim*_*hev 7

这种转变:

<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>
Run Code Online (Sandbox Code Playgroud)

"my:x"命名空间中删除任何元素并将其放入"无命名空间".

例如,应用于以下XML文档时:

<t>
  <x:a  xmlns:x="my:x"/>
</t>
Run Code Online (Sandbox Code Playgroud)

产生了想要的正确结果:

<t>
   <a/>
</t>
Run Code Online (Sandbox Code Playgroud)

要仅从特定命名空间中删除特定元素,必须使覆盖标识规则的模板更具体,以仅匹配所需元素.