2009-08-26 69 views
0

我正在處理肥皂響應文件,我們的要求是在請求期間將捕獲的某些數據添加到響應中。我在這裏有這個XML響應,就像使用XSLT文件將某些數據添加到其頭部分一樣。請指教。使用XSLT將標記插入到肥皂標題中

實際效應初探

<soap:Envelope xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Header> 
     <wsse:Security> 
     <wsu:Timestamp wsu:Id="Timestamp-7cd6d5e5"> 
      <wsu:Created>2009-08-26</wsu:Created> 
     </wsu:Timestamp> 
     </wsse:Security> 
    </soap:Header> 
    <soap:Body> 
     <GetProxy> 
     <ProxiesList/> 
     </GetProxy> 
    </soap:Body> 
</soap:Envelope> 

需要一個XSLT將其轉換爲

<soap:Envelope xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Header> 
     <wsse:Security> 
     <wsu:Timestamp wsu:Id="Timestamp-7cd6d5e5"> 
      <wsu:Created>2009-08-26</wsu:Created> 
     </wsu:Timestamp> 
     </wsse:Security> 
     <ut:reqCode xmlns:ut="temp.org"> 
     <ut:reqInfo>information from request</ut:reqInfo> 
     </ut:reqCode> 
    </soap:Header> 
    <soap:Body> 
     <GetProxy> 
     <ProxiesList/> 
     </GetProxy> 
    </soap:Body> 
</soap:Envelope> 

我很欣賞你help.Thanks

回答

3

插入東西放到XML一個有用的模式是使用identity transform複製所有內容並覆蓋它,以覆蓋要更改的標籤:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
       xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
       version="1.0"> 
    <xsl:output method="xml" 
       indent="yes"/> 

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

    <!-- special handling for soap:Header --> 
    <xsl:template match="soap:Header"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 

     <!-- insert the following inside the soap:Header tag --> 
     <ut:reqCode xmlns:ut="temp.org"> 
     <ut:reqInfo>information from request</ut:reqInfo> 
     </ut:reqCode> 

    </xsl:copy> 
    </xsl:template> 

</xsl:stylesheet> 

這基本上只是複製所有內容,但對於soap:Header複製其內容後,添加了一些額外的內容。