2011-04-01 102 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