Skip to Content
avatar image
Former Member

XSLT code to get SAOP_Body from the SOAP Response

Hello experts,

I am working on SAP with Sales force integration a synchronous scenario . I am trying to fetch only the Body part of the soap response message, but my below xslt is not producing desired output.

Response Message structure:

http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn: enterprise.soap.sforce.com" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xmlns:sf="urn: sobject.enterprise.soap.sforce.com">

XSLT code i tried:

- http://www.w3.org/1999/XSL/Transform" xmlns:SOAP-ENV=" http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xmlns:sf="urn: sobject.enterprise.soap.sforce.com" version="1.0"> -

I have followed different posts in scn regarding on the same requirement, but nothing was helped to resolve my issue. Please can anyone give me suggestion to resolve my issue ?

Thanks,

Siva.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Best Answer
    Mar 24, 2017 at 08:28 AM

    Hi Siva,

    Have you tried with XSLT?, check my answer here https://archive.sap.com/discussions/thread/3684914

    Regards.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 24, 2017 at 01:30 PM

    Hi Vila,

    Thank you for your response. I followed the link you shared and tried the same,but still my XSLT is not producing desired XML output...

    SOAP Response Message:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
       <soapenv:Header>
          <LimitInfoHeader>
              <limitInfo> 
                <current></current> 
                <limit></limit>      
           <type></type>    
          </limitInfo>
          </LimitInfoHeader>
       </soapenv:Header>   
     <soapenv:Body>   
        <queryResponse>    
          <result>      
           <done></done>
            <ueryLocator xsi:nil="true"/>    
              <records xsi:type="sf:Opportunity">
                   <sf:Id xsi:nil="true"/>            
                   <sf:Amount></sf:Amount>           
                   <sf:CloseDate></sf:CloseDate>
                   <sf:Name></sf:Name>         
              </records>
           <size></size>       
       </result>    
       </queryResponse> 
       </soapenv:Body
    
    </soapenv:Envelope>

    XSLT Code:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soapenv="http://www.w3.org/2001/12/soap-envelope" xmlns="urn:enterprise.soap.sforce.com">
    <xsl:output method="xml" encoding="utf-8" indent="no"/>
       
    <xsl:template match="/">
          <xsl:if test="soapenv:Envelope/soapenv:Body">                                 
       <xsl:copy-of select="/soapenv:Envelope/soapenv:Body/child::*" />
         </xsl:if>
       </xsl:template>
                      
    </xsl:stylesheet>
    

    Plz check and correct my code. My requirement is to get the fields under "<records>" segment.

    Thanks,

    Siva.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 25, 2017 at 02:03 PM

    I was able to get the fields under <records> segment using below XPath

    /soapenv:Envelope/soapenv:Body/ns1:queryResponse/ns1:result/ns1:records/child::*

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 27, 2017 at 04:39 AM

    Hi Amith,

    I have tried with the below xslt code but it is not working for me.. i am testing my code at below site

    http://www.freeformatter.com/xsl-transformer.html

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soapenv="http://www.w3.org/2001/12/soap-envelope" xmlns="urn:enterprise.soap.sforce.com">
    <xsl:output method="xml" encoding="utf-8" indent="no"/>
       
    <xsl:template match="/">
          <xsl:if test="soapenv:Envelope/soapenv:Body">                                 
       <xsl:copy-of select="/soapenv:Envelope/soapenv:Body/ns1:queryResponse/ns1:result/ns1:records/child::*" />
         </xsl:if> 
       </xsl:template>
                      
    </xsl:stylesheet>
    
    

    plz correct me where i am doing wrong...

    Thanks,

    siva.

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 27, 2017 at 06:31 AM

    Hi,

    With this XSLT:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:n="urn:enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
        <xsl:output method="xml" encoding="utf-8" indent="yes"/>
        <xsl:template match="/">
            <records>
            <xsl:copy-of select="//n:records/*"/>
            </records>
        </xsl:template>
    </xsl:stylesheet>
    
    
    
    

    you get:

    <?xml version="1.0" encoding="utf-8"?>
    <records xmlns:n="urn:enterprise.soap.sforce.com" xmlns:sf="urn:sobject.enterprise.soap.sforce.com" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <sf:Id xsi:nil="true" xmlns="urn:enterprise.soap.sforce.com"/>
        <sf:Amount xmlns="urn:enterprise.soap.sforce.com"/>
        <sf:CloseDate xmlns="urn:enterprise.soap.sforce.com"/>
        <sf:Name xmlns="urn:enterprise.soap.sforce.com"/>
    </records>

    If you want to remove the namespaces, you can with a second xslt:

    <?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">   <xsl:output indent="yes" method="xml" encoding="utf-8"/>   <xsl:template match="*">     <xsl:element name="{local-name()}">       <xsl:apply-templates select="@* | node()"/>     </xsl:element>   </xsl:template>   <!-- template to copy attributes -->   <xsl:template match="@*">     <xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute>   </xsl:template>   <!-- template to copy the rest of the nodes -->   <xsl:template match="comment() | text() | processing-instruction()">     <xsl:copy/>   </xsl:template></xsl:stylesheet>

    And you will get:

    <?xml version="1.0" encoding="utf-8"?>
    <records>   <Id nil="true"/>   <Amount/>   <CloseDate/>   <Name/></records>

    Regards.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 27, 2017 at 09:00 AM

    Hi Vila thank you so much for your prompt response. It is perfectly working now.

    Thank you Amit for your answer.

    Add comment
    10|10000 characters needed characters exceeded