2013-12-17 79 views
0

從XML刪除所有屬性的一個根元素我有一個很大的XML文件的以下根元素:XSLT使用XSLT

<Interchange xmlns='http://www.e2b.no/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' 
xsi:schemaLocation='http://www.e2b.no/XMLSchema Interchange'> 

我需要得到

<Interchange> 

請指點,對不起,我不會放棄我的嘗試的例子 我將使用基本的模板:

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
          xmlns:e2b='http://www.e2b.no/XMLSchema'> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" /> 
<xsl:strip-space elements="*" /> 

<!-- copy everything as-is apart from exceptions below --> 
<xsl:template match="node() | @*"> 
    <xsl:copy> 
     <xsl:apply-templates select="node() | @*"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="e2b:Interchange"> 
<Interchange> 
<xsl:apply-templates/> 
</Interchange> 
</xsl:template> 

</xsl:stylesheet> 

當我測試我ACCID entally發送大XML輸入與開頭:

<?xml version='1.0' encoding='ISO-8859-1'?> 
<Interchange> 

insted的

<?xml version='1.0' encoding='ISO-8859-1'?> 
<Interchange xmlns='http://www.e2b.no/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' 
xsi:schemaLocation='http://www.e2b.no/XMLSchema Interchange'> 

因爲我對我以前回答過的問題積極。

請諮詢,任何想法。

+0

如果給出你的[上一個問題]的答案(http://stackoverflow.com/questions/20636169/xslt-remove-all-attribute-for-one-element-from-xml-using-xslt)didn' t爲你工作,你應該接受並繼續,而不是打開一個新的,類似的問題 –

回答

1

使用

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
          xmlns:e2b='http://www.e2b.no/XMLSchema' 
exclude-result-prefixes="e2b"> 



<!-- copy everything as-is apart from exceptions below --> 
<xsl:template match="node() | @*"> 
    <xsl:copy> 
     <xsl:apply-templates select="node() | @*"/> 
    </xsl:copy> 
</xsl:template> 

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

<xsl:template match="/e2b:Interchange"> 
    <xsl:element name="{local-name()}"> 
    <xsl:apply-templates/> 
    </xsl:element> 
</xsl:template> 

</xsl:stylesheet> 

這種做法是必要的元素從e2b命名空間變換到沒有命名空間。

+0

謝謝,它真的有效。 – user3042795