2017-10-12 6 views
0

주어진 입력 xml을 아래 표시된 것처럼 출력으로 변환하는 방법. wsse : Security 헤더를 완전히 제거하여 입력 xml을 변환해야하며 EventUser 값을 Username 노드 값으로 업데이트해야합니다. 나는 아래 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에서 네임 스페이스를 차지하지 않았습니다. tns: 접두사로 표시로 XML에서 요소가 여러 네임 스페이스에있는합니다 (EventUser 요소는 네임 스페이스 http://g22.test01.org/test02/RF입니다. 당신은 Username을 선택하는 것입니다 템플릿이 EventUser 일치하는 wsse:Security 요소
  2. 을 제거하기 위해 아무것도 코딩되지 않은
  3. 하는 . UsernameEventUser의 아이 일 경우에만 당신은 실제로 비누에서 선택해야합니다 : 헤더

하면이 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>