2011-02-11 26 views
5

我見過類似的問題,但對我而言仍然不清楚。我不希望「n1」命名空間出現在輸出文件中節點的屬性中。但是我必須在xslt文件中創建「n1」命名空間才能使xpath正常工作。謝謝。XSLT在輸出文件中注入不需要的名稱空間

XSLT:

<xsl:stylesheet version="1.0" 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     xmlns:n1="http://www.spicefactory.org/parsley" 
     xmlns="http://www.spicefactory.org/parsley" 
     > 

    <xsl:output method="xml" indent="no"/> 

    <xsl:template match="node()|@*"> 
     <xsl:copy> 
      <xsl:apply-templates select="node()|@*"/> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="n1:object[@type='mytype1']"> 
     <object type="mytype2"> 
     <xsl:apply-templates select="node()"/> 
     </object> 
    </xsl:template> 

摘自輸出XML文件:

<object type="mytype2" xmlns:n1="http://www.spicefactory.org/parsley"> 

回答

13

使用exclude-result-prefixes<xsl:stylesheet>元素屬性。

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:n1="http://www.spicefactory.org/parsley" 
    xmlns="http://www.spicefactory.org/parsley" 
    exclude-result-prefixes="n1" 
    > 
+0

+1正確,簡短但正確。 – 2011-02-11 21:21:43