cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT code to get SAOP_Body from the SOAP Response

0 Kudos

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:

<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> <queryLocator 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 i tried:

<?xml version="1.0"?> -<xsl:stylesheet xmlns:xsl="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"> <xsl:output version="1.0" indent="yes" encoding="UTF-8" method="xml"/> -<xsl:template match="/"> <xsl:copy-of select="SOAP:Env:Envelope/SOAP-ENV:Body/*"/> </xsl:template> </xsl:stylesheet>

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.

Accepted Solutions (1)

Accepted Solutions (1)

iaki_vila
Active Contributor
0 Kudos

Hi Siva,

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

Regards.

Answers (5)

Answers (5)

0 Kudos

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

Thank you Amit for your answer.

iaki_vila
Active Contributor
0 Kudos

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.

0 Kudos

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.

Former Member
0 Kudos

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

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

0 Kudos

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.