2016-04-07 64 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