2009-10-28 80 views
5

我正嘗試使用xsl/xslt(SSIS中XML任務的要求)從以下xml中刪除屬性xmlns="http://webdev2003.test.com"。考慮到大文件大小,什麼是正確的方法。 〜40MBRmove xmlns屬性

<?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> 
+0

SSIS中沒有適當的命名空間處理嗎? – Tomalak

回答

0

什麼

<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> 

+0

我從XML記事本中收到一個錯誤 - 無法創建具有本地名稱「xmlns」和空名稱空間URI的屬性。分別在MSVS錯誤中:無法創建具有本地名稱「xmlns」和空名稱空間URI的屬性。 – decompiled

1

我認爲你可以刪除this article中描述的名稱空間聲明。看起來您可能需要在樣式表中爲名稱空間聲明一個前綴,然後將其添加到exclude-result-prefixes屬性中。

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".