2011-04-01 22 views
2

我需要将标签从一个位置移动到另一个位置。使用XSLT更改SOAP XML中的标签位置

请求如下:

<Envelope> 
    <Header> 
     <Assertion></Assertion> 
     <Security></Security> 
    </Header> 
</Envelope> 

但我需要一个XSLT把断言标记内安全如下:

<Envelope> 
    <Header> 
     <Security> 
      <Assertion></Assertion> 
     </Security> 
    </Header> 
</Envelope> 

我感谢你的帮助。由于

回答

0

以下样式:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="@*|node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|node()" /> 
     </xsl:copy> 
    </xsl:template> 
    <xsl:template match="Assertion" /> 
    <xsl:template match="Security"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|node()"/> 
      <xsl:copy-of select="../Assertion"/> 
     </xsl:copy> 
    </xsl:template> 
</xsl:stylesheet> 

...产生当适用于您提供的源所需的输出:

<Envelope> 
    <Header> 
     <Security> 
      <Assertion></Assertion> 
     </Security> 
    </Header> 
</Envelope> 
+0

两点意见:使用'../ Assertion'而不是绝对的表达更一般; 'xsl:copy-of'指令应该位于'xsl:apply-templates'后面的属性中。 – 2011-04-01 14:57:12

+0

@Ajjandro - 好的建议。更新。 – 2011-04-01 15:26:30

+0

谢谢,很好用 – BVNM 2011-04-01 20:13:31