2017-10-12 133 views
0

如何將給定輸入xml轉換爲輸出,如下所示。 應通過完全刪除wsse:Security標頭來變換輸入xml,並且必須使用Username節點值更新EventUser值。 我在xlst下面試過。它不工作輸入輸出轉換刪除節點和更新節點

XLST -

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

輸入 -

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soapenv:Header> 
     <wsse:Security mustUnderstandValue="1" 
        xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
     <wsse:UsernameToken id="UsernameToken-274"> 
      <wsse:Username>MyUsername</wsse:Username> 
      <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</wsse:Password> 
     </wsse:UsernameToken> 
     </wsse:Security> 
    </soapenv:Header> 
    <soapenv:Body> 
     <axis2ns682:Create xmlns:axis2ns682="http://g22.test01.org/test02/RF"> 
     <tns:CreateDetails xmlns:tns="http://g22.test01.org/test02/RF"> 
      <tns:EventUser>Event</tns:EventUser> 
      <tns:PreApprovedTemplateID>221398</tns:PreApprovedTemplateID> 
      <tns:Priority>High</tns:Priority> 
      <tns:PlannedImplementation_Start>2017-09-29</tns:PlannedImplementation_Start> 
     </tns:CreateDetails> 
     </axis2ns682:Create> 
    </soapenv:Body> 
</soapenv:Envelope> 

輸出 -

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soapenv:Header>  
    </soapenv:Header> 
    <soapenv:Body> 
     <axis2ns682:Create xmlns:axis2ns682="http://g22.test01.org/test02/RF"> 
     <tns:CreateDetails xmlns:tns="http://g22.test01.org/test02/RF"> 
      <tns:EventUser>MyUsername</tns:EventUser> 
      <tns:PreApprovedTemplateID>221398</tns:PreApprovedTemplateID> 
      <tns:Priority>High</tns:Priority> 
      <tns:PlannedImplementation_Start>2017-09-29</tns:PlannedImplementation_Start> 
     </tns:CreateDetails> 
     </axis2ns682:Create> 
    </soapenv:Body> 
</soapenv:Envelope> 

回答

0

你有三個問題,你的XSLT

  1. 您尚未考慮XSLT中的名稱空間。在你的XML中,元素是在不同的命名空間(該EventUser元素在命名空間http://g22.test01.org/test02/RFtns:前綴表示。
  2. 您還沒有編碼的任何刪除wsse:Security元素
  3. 模板匹配EventUser是選擇Username,這。將只會如果Username是的EventUser孩子實際上,你需要從肥皂中選擇:頭

試試這個XSLT

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
       xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
       xmlns:tns="http://g22.test01.org/test02/RF" 
       xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
       version="1.0"> 

    <xsl:template match="wsse:Security" /> 

    <xsl:template match="tns:EventUser"> 
     <xsl:copy> 
      <xsl:value-of select="//soapenv:Header/wsse:Security/wsse:UsernameToken/wsse:Username"/> 
     </xsl:copy> 
    </xsl:template> 

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