Rmove xmlns attribute
I am trying to remove the attribute开发者_StackOverflow社区 xmlns="http://webdev2003.test.com"
from the following xml using xsl/xslt, a requirement of the XML Task in SSIS. What is a proper methodology considering a large file size. ~40mb
<?xml version="1.0" encoding="utf-16"?>
<ArrayOfAccount xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Account>
<FirstName xmlns="http://webdev2003.test.com/">John</FirstName>
<LastName xmlns="http://webdev2003.test.com/">Smith</LastName>
</Account>
</ArrayOfAccount>
I hate when I answer my own questions, but the credit goes to - http://blogs.msdn.com/kaevans/archive/2003/06/13/8679.aspx
The first part of the example lists how to remove all attributes which in my scenario works. Perhaps there is a better solution?
I think you can remove the namespace declarations as described in this article. It looks like you might have to declare a prefix for the namespace in your stylesheet before adding it to the exclude-result-prefixes attribute.
You can prevent this from happening with the xsl:stylesheet element's exclude-result-prefixes attribute. This attribute's name can be confusing, because the namespace prefixes will still show up in the result tree. It doesn't mean "exclude the prefixes in the result"; it means "exclude the namespaces with these prefixes".
What about
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsl:template match="*">
<xsl:element name="{name()}">
<xsl:apply-templates select="attribute::*"/>
<xsl:if test="namespace-uri()!='http://webdev2003.test.com/' and
namespace-uri()!=''">
<xsl:attribute name="xmlns">
<xsl:value-of select="namespace-uri()"/>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
?
精彩评论