cancel
Showing results for 
Search instead for 
Did you mean: 

Issues in xslt conversion in SAP PI

Former Member
0 Kudos

Hi Experts,

I have one xml as below:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">

<s:Body>

<TransferFileResponse xmlns="http://tempuri.org/">

<TransferFileResult xmlns:a="http://abc.com/gds.externalServices/data" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

<a:Errors xmlns:b="https://ccs.abc.com.au/Internal/">

<b:ServiceRequestError>

  <b:ErrorCode>InternalError</b:ErrorCode>

  <b:ErrorMessage>Error Occurred. Please refer the episode id 'e2f2bc27' for further help.</b:ErrorMessage>

  <b:ErrorTime>2016-09-12T13:43:32.7413505+10:00</b:ErrorTime>

  </b:ServiceRequestError>

<b:ServiceRequestError>

  <b:ErrorCode>InvalidData</b:ErrorCode>

  <b:ErrorMessage>[MELYDEVAPP816] - Invalid reference code '95' specified.</b:ErrorMessage>

  <b:ErrorTime>2016-09-12T13:42:54.5554226+10:00</b:ErrorTime>

  </b:ServiceRequestError>

  </a:Errors>

  <a:IsSuccessful>false</a:IsSuccessful>

  <a:ServiceReferenceId>82338378</a:ServiceReferenceId>

  </TransferFileResult>

  </TransferFileResponse>

  </s:Body>

  </s:Envelope>

I want the output to be generated as below:

<TransferFileResponse xmlns="http://tempuri.org/">

<TransferFileResult xmlns:a="http://abc.com/gds.externalServices/datacontracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

<Errors xmlns="http:/abc.com/gds.externalServices/datacontracts">

<ServiceRequestError xmlns="https://ccs.abc.com.au/CCSConnectInternal/">

  <ErrorCode>InternalError</ErrorCode>

  <ErrorMessage>Error Occurred. Please refer the episode id 'e2f2bc27' for further help.</ErrorMessage>

  <ErrorTime>2016-09-12T13:43:32.7413505+10:00</ErrorTime>

  </ServiceRequestError>

<ServiceRequestError xmlns="https://ccs.abc.com.au/CCSConnectInternal/">

  <ErrorCode>InvalidData</ErrorCode>

  <ErrorMessage>[MELYDEVAPP816] - Invalid reference code '95' specified.</ErrorMessage>

  <ErrorTime>2016-09-12T13:42:54.5554226+10:00</ErrorTime>

  </ServiceRequestError>

  </Errors>

  <IsSuccessful xmlns="http://abc.com/gds.externalServices/datacontracts">false</IsSuccessful>

  <ServiceReferenceId xmlns="http://abc.com/gds.externalServices/datacontracts">82338378</ServiceReferenceId>

  </TransferFileResult>

</TransferFileResponse>

Could you please let me know how can I use xslt code to generate the output xml. I have tried with some but not able to get the exact output.

Appreciate your help.

Regards,

Treya

Accepted Solutions (1)

Accepted Solutions (1)

GauravKant
Contributor
0 Kudos

Hi Treya,

You want to remove SOAP envelope and prefix. Kindly check the below thread hope you will get solution for this.

There are many thread in SCN for this you can check others also.

Regards,

Gaurav

Answers (3)

Answers (3)

Former Member
0 Kudos

Thankyou all for such useful suggestions.

I applied the solution provided by Gaurav according to my requirement and got the expected output.

Thanks & Regards,

Treya Dasgupta

Former Member
0 Kudos

Actually I have more than one requirement:

  • I have to remove the soap envelope part, which is possible by the solution given by Gaurav.
  • I have to remove the prefix- i am only able to remove the starting prefix 'a' or 'b' but not the ones in xmlns part.
  • I have to explicitly include the xmlns namespace in some elements even though the input xml does not contain so, e.g- in <IsSuccessful> I need to incude xmlns="http://abc.com/gds.externalServices/datacontracts" inside it.

So, if you could please assist me in the last point specially then it would be great.

Regards,

Treya

former_member190293
Active Contributor
0 Kudos

Hi Treya!

I guess it's not the best XSL transformation , but you could try it for your requirement:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

                         xmlns:usr="urn://user_values"

                         xmlns:a="http://abc.com/gds.externalServices/datacontracts"

                         xmlns:i="http://www.w3.org/2001/XMLSchema-instance"

     exclude-result-prefixes="a i"

     version="1.0">

  

     <xsl:output indent="yes"/>

  

     <usr:ns_list xml:space="preserve">

          <item key="TransferFileResponse">http://tempuri.org/</item>

          <item key="Errors">http://abc.com/gds.externalServices/datacontracts</item>

          <item key="ServiceRequestError">https://ccs.abc.com.au/CCSConnectInternal/</item>

          <item key="IsSuccessful">http://abc.com/gds.externalServices/datacontracts</item>

          <item key="ServiceReferenceId">http://abc.com/gds.externalServices/datacontracts</item>

     </usr:ns_list>

  

     <xsl:variable name="nsPatterns" select="document('')/*/usr:ns_list/*"/>

     <xsl:variable name="v_ns_a" select="document('')/*/namespace::*[name()='a']"/>

     <xsl:variable name="v_ns_i" select="document('')/*/namespace::*[name()='i']"/>

  

     <xsl:template match="/">

     <xsl:apply-templates select="//*[local-name()='TransferFileResponse']">

          <xsl:with-param name="elementNS" select="''"></xsl:with-param>

     </xsl:apply-templates>

     </xsl:template>

  

     <xsl:template name="createNodes" match="*">

          <xsl:param name="elementNS"><xsl:value-of select="namespace-uri()"/></xsl:param>

          <xsl:variable name="nodeName" select="local-name()"/>

          <xsl:variable name="subElementsNS">

               <xsl:choose>

                    <xsl:when test="$nsPatterns[@key=$nodeName]">

                         <xsl:value-of select="$nsPatterns[@key=$nodeName][1]"/>

                    </xsl:when>

                    <xsl:otherwise>

                         <xsl:value-of select="$elementNS"/>

                    </xsl:otherwise>

               </xsl:choose>  

          </xsl:variable>

      

          <xsl:element name="{$nodeName}" namespace="{$subElementsNS}">

               <xsl:if test="$nodeName='TransferFileResult'">

                    <xsl:copy-of select="$v_ns_a"/>

                    <xsl:copy-of select="$v_ns_i"/>

               </xsl:if>

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

                    <xsl:with-param name="elementNS" select="$subElementsNS"/>

               </xsl:apply-templates>

          </xsl:element>

    </xsl:template>

  

     <xsl:template match="comment() | text() | processing-instruction()">

          <xsl:copy/>

     </xsl:template>

  

</xsl:stylesheet>

Source XML:

<?xml version="1.0" encoding="UTF-8"?>

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">

     <s:Body>

          <TransferFileResponse xmlns="http://tempuri.org/">

               <TransferFileResult xmlns:a="http://abc.com/gds.externalServices/data" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

                    <a:Errors xmlns:b="https://ccs.abc.com.au/Internal/">

                         <b:ServiceRequestError>

                              <b:ErrorCode>InternalError</b:ErrorCode>

                              <b:ErrorMessage>Error Occurred. Please refer the episode id 'e2f2bc27' for further help.</b:ErrorMessage>

                              <b:ErrorTime>2016-09-12T13:43:32.7413505+10:00</b:ErrorTime>

                         </b:ServiceRequestError>

                         <b:ServiceRequestError>

                              <b:ErrorCode>InvalidData</b:ErrorCode>

                              <b:ErrorMessage>[MELYDEVAPP816] - Invalid reference code '95' specified.</b:ErrorMessage>

                              <b:ErrorTime>2016-09-12T13:42:54.5554226+10:00</b:ErrorTime>

                         </b:ServiceRequestError>

                    </a:Errors>

                    <a:IsSuccessful>false</a:IsSuccessful>

                    <a:ServiceReferenceId>82338378</a:ServiceReferenceId>

               </TransferFileResult>

          </TransferFileResponse>

     </s:Body>

</s:Envelope>

Result XML:

<?xml version="1.0" encoding="utf-8"?>

<TransferFileResponse xmlns="http://tempuri.org/">

     <TransferFileResult xmlns:a="http://abc.com/gds.externalServices/datacontracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

          <Errors xmlns="http://abc.com/gds.externalServices/datacontracts">

               <ServiceRequestError xmlns="https://ccs.abc.com.au/CCSConnectInternal/">

                    <ErrorCode>InternalError</ErrorCode>

                    <ErrorMessage>Error Occurred. Please refer the episode id 'e2f2bc27' for further help.</ErrorMessage>

                    <ErrorTime>2016-09-12T13:43:32.7413505+10:00</ErrorTime>

               </ServiceRequestError>

               <ServiceRequestError xmlns="https://ccs.abc.com.au/CCSConnectInternal/">

                    <ErrorCode>InvalidData</ErrorCode>

                    <ErrorMessage>[MELYDEVAPP816] - Invalid reference code '95' specified.</ErrorMessage>

                    <ErrorTime>2016-09-12T13:42:54.5554226+10:00</ErrorTime>

               </ServiceRequestError>

          </Errors>

          <IsSuccessful xmlns="http://abc.com/gds.externalServices/datacontracts">false</IsSuccessful>

          <ServiceReferenceId xmlns="http://abc.com/gds.externalServices/datacontracts">82338378</ServiceReferenceId>

     </TransferFileResult>

</TransferFileResponse>

Regards, Evgeniy.

former_member190293
Active Contributor
0 Kudos

Hi Treya!

Are you sure that you need output like above?

For example, your prefixes "a" and "i" are never used in described output XML structure.

Regards, Evgeniy.