2017-06-15 50 views
2

我有以下XML:XSLT - 删除重复的命名空间声明

<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="xmldsig"> 
    <ds:SignedInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> 
    </ds:SignedInfo> 
    <ds:SignedInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> 
    <ds:SignedInfoData xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/> 
    </ds:SignedInfo/> 
</ds:Signature> 

的问题是,当我需要<ds:Signature>第一ds命名空间声明。以下(<ds:SignedInfo><ds:SignedInfoData>)不是必需的。有没有办法使用XSLT 1.0得到这个输出删除重复的命名空间声明:

<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="xmldsig"> 
    <ds:SignedInfo> 
    </ds:SignedInfo> 
    <ds:SignedInfo> 
    <ds:SignedInfoData/> 
    </ds:SignedInfo> 
</ds:Signature> 

回答

1

省去了重复的命名空间声明的东西,仅通过复制输入发生,例如与身份转变http://xsltransform.net/jxDigU1/1

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

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

或更简单的仍然是