2016-04-07 62 views
0

我是新來的XSLT,我想從下面的XML刪除元素「輸入」XSLT身份轉換:刪除元素

我輸入XML:

<ns1:Input xmlns:ns1="http://www.test.org/"> 
    <Process xmlns="http://www.acord.org/...." 
       xsi:schemaLocation="http://www.acord.org/schema/... "> 
    ..... 
    </Process> 
</ns1:Input> 

預期輸出:

<Process xmlns="http://www.acord.org/...." 
      xsi:schemaLocation="http://www.acord.org/schema/... "> 
     ..... 
</Process> 

我使用恆等變換一樣,

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

因此,它將整個xml複製到目標xsd中,但它正在使用要刪除的「input」元素進行復制。 欣賞任何快速幫助。

感謝, cdhar

回答

0

添加模板

<xsl:template match="ns1:Input"> 
    <xsl:apply-templates/> 
</xsl:template> 

在任何情況下,你可能會得到Process元素的根命名空間聲明,以便與XSLT 2.0中可能需要您的身份轉變爲使用<xsl:copy copy-namespaces="no">...http://xsltransform.net/bFN1yag

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> 

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

    <xsl:template match="ns1:Input" xmlns:ns1="http://www.test.org/"> 
     <xsl:apply-templates/> 
    </xsl:template> 
</xsl:transform> 

或者您需要使用<xsl:element name="{name()}" namespace="{namespace-uri()}">而不是xsl:copy在XSLT 1.0中創建元素。

+0

非常感謝馬丁。奇蹟般有效。謝謝!! – user3401234