2016-12-02 59 views
0

我想刪除現有名稱空間並向我的XML文檔添加另一個名稱空間。當我沒有添加屬性時,它正在工作。現在,當我添加一個屬性「ID」刪除代碼不起作用。使用XSLT刪除名稱空間不起作用

我的XML文件是:

<?xml version="1.0" encoding="UTF-8"?> 

<n0:eCPR xmlns:prx="urn:sap.com:proxy:DV4:/1SAI/TAS1F59A417878D36573F1D:700:2013/05/24" xmlns:n0="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd"> 

<n0:employees> 
    <n0:employee> 
    <n0:name id="20019768">Paul John</n0:name> 
</n0:employee> 
</n0:employees> 
</n0:eCPR> 

我希望它是什麼:

<CPR:eCPR xmlns:CPR="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd"> 
<CPR:employees> 
    <CPR:employee> 
    <CPR:name id="12345">JOHN SMITH</CPR:name> 
    </CPR:employee> 
</CPR:employees> 
</CPR:eCPR> 

的XSLT我申請(用我以前的帖子Unable to Update the Namespace of XML Document前的工作)是代碼:

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:CPR="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
<xsl:strip-space elements="*"/> 

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

</xsl:stylesheet> 

回答

1

如果你的輸入有屬性,你需要這樣做:

<xsl:copy-of select="@*"/> 

在此之前:

<xsl:apply-templates/> 
+0

你搖滾的人!總是尋求幫助! –