logo

去除 XML 文件中的全部名称空间

作者:孟宪会 阅读:941 发表于:2010-10-15 12:17:20

使用 XSLT 进行转换。代码如下:

XSL 代码
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
<xsl:output method="xml" indent="no" omit-xml-declaration="yes"/>
  
<xsl:template match="/|comment()|processing-instruction()">
    
<xsl:copy>
      
<xsl:apply-templates/>
    
</xsl:copy>
  
</xsl:template>

  
<xsl:template match="*">
    
<xsl:element name="{local-name()}">
      
<xsl:apply-templates select="@*|node()"/>
    
</xsl:element>
  
</xsl:template>

  
<xsl:template match="@*">
    
<xsl:attribute name="{local-name()}">
      
<xsl:value-of select="."/>
    
</xsl:attribute>
  
</xsl:template>

</xsl:stylesheet>