2016-07-27 8 views
0

Ich habe eine Anforderung, wo ich eine XML-Nachricht in eine Soap-Nachricht übertragen muss. Hier ist der Eingang I als Teil einer Anfrage bin immer:Transfor XML in SOAP und wählen Sie einige Elemente anstelle von allen

<response status="200"> 
    <CustomField> 
     <CustomList> 
      <List>123</List> 
      <StatusList>four</StatusList> 
      <ErrorMessage>failed</ErrorMessage> 
     </CustomList> 
     <CustomList> 
      <List>acv</List> 
      <StatusList>three</StatusList> 
      <ErrorMessage>failed</ErrorMessage> 
     </CustomList> 
    </CustomField> 
</response> 

Die intented Ausgabe lautet:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> 
    <soap:Header/> 
    <soap:Body> 
     <wsdl:statusResponse xmlns:wsdl="http://ee.co.uk/status/wsdl"> 
      <output> 
       <Listentifier> 
          <customList> 
           <list>123</list> 
           <statusList>four</statusList> 
          </customList> 
          <customList> 
           <list>acv</list> 
           <statusList>three</statusList> 
          </customList> 
       </Listentifier> 
      </output> 
     </wsdl:statusResponse> 
    </soap:Body> 
</soap:Envelope> 

Ich habe versucht, die folgenden XSL, die mir alle das Element aus dem Eingang gibt, aber Ich brauche einige ausgewählte Elemente in meiner Ausgabe. Wie kann ich das machen?

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wsdl="http://ee.co.uk/status/wsdl" xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> 
    <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>  
    <xsl:strip-space elements="*"/> 

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

    <xsl:template match="/"> 

     <xsl:if test="/response/CustomField/CustomList/List"> 
      <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> 
       <soap:Header/> 
       <soap:Body> 

        <wsdl:statusResponse> 
         <output> 
          <Listentifier> 
           <xsl:apply-templates/> 
          </Listentifier> 
         </output> 
        </wsdl:statusResponse> 
       </soap:Body> 
      </soap:Envelope> 
     </xsl:if> 
    </xsl:template> 

    <xsl:template match="List"> 
     <list> 
      <xsl:apply-templates/> 
     </list> 
    </xsl:template> 

    <xsl:template match="StatusList"> 
     <statusList> 
      <xsl:apply-templates/> 
     </statusList> 
    </xsl:template> 
</xsl:stylesheet> 
+0

XML ist case-sensitive; Willst du wirklich eine 'customList' und eine' CustomList'? –

+0

Beide sind customList, es war ein Tippfehler. Es wurde aktualisiert. – Sammy

Antwort

1

Versuchen:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
<xsl:strip-space elements="*"/> 

<xsl:template match="/response"> 
    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> 
     <soap:Header/> 
     <soap:Body> 
      <wsdl:statusResponse xmlns:wsdl="http://ee.co.uk/status/wsdl"> 
       <output> 
        <Listentifier> 
         <xsl:apply-templates/>  
        </Listentifier> 
       </output> 
      </wsdl:statusResponse> 
     </soap:Body> 
    </soap:Envelope> 
</xsl:template> 

<xsl:template match="CustomList"> 
    <customList> 
     <list> 
      <xsl:value-of select="List"/> 
     </list> 
     <statusList> 
      <xsl:value-of select="StatusList"/> 
     </statusList> 
    </customList> 
</xsl:template> 

</xsl:stylesheet> 
+0

Danke Michael. Es hat funktioniert. – Sammy