cancel
Showing results for 
Search instead for 
Did you mean: 

converting XML fields into single json string

nagaraju_cygnet
Participant
0 Kudos

Dear Experts,

 

My scenario : proxy <--> PI <---> rest         mode of communication : Synchronous

i have a requirement, i am getting 3 xml fields as shown in the below  in the input payload need to convert them as a single json string. could you please help on this to write an XSLT code. i am new to this xslt code.

input fields : 

client_id

client_secret

grant_type

 

Thanks in advance.

 

Best Regards,

Nagaraju

View Entire Topic
ismail-6154
Discoverer
0 Kudos

Hi Nagaraju,

The below XSLT will suits for requirement,

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

    <xsl:output method="text" encoding="UTF-8"/>

       <xsl:template match="/">

        <xsl:text>{</xsl:text>

        <xsl:text>"client_id": "</xsl:text>

        <xsl:value-of select="/request/client_id"/>

        <xsl:text>", </xsl:text>

        <xsl:text>"client_secret": "</xsl:text>

        <xsl:value-of select="/request/client_secret"/>

        <xsl:text>", </xsl:text>

        <xsl:text>"grant_type": "</xsl:text>

        <xsl:value-of select="/request/grant_type"/>

        <xsl:text>"}</xsl:text>

    </xsl:template>

</xsl:stylesheet>

Thanks,

Ismail

 

ismail6154_0-1716959981527.png

nagaraju_cygnet
Participant
0 Kudos

Dear Ismail,

thanks for you immediate response. sorry its my bad i have not given clarity in my question about my requirment, i have checked in the operation mapping but i am not getting the proper output what i have expected.

let me explain my requirement first. i have to send the data ( 3 fields ) to the rest api in the body level especially  x-www-form-urlencoded. i have read some of few blogs in sap but they have achieved this requirement through java mapping but i don't want to go this approach because i don't have any knowledge on java. so i choose xslt mapping approach. even i have tried the xslt code in the chatgpt also but not getting as excepted, chatgpt code level getting single sting as a out put but not getting values. i would request you could you please make the changes in the chatgpt code if possible.

your xslt code response in Operation mapping:

nagaraju_cygnet_0-1716961690432.png

 

My requirement in the postman collection :

nagaraju_cygnet_1-1716961865192.png

 

my request payload in the operation mapping :

<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_x_www_form_urlencoded_REQ xmlns:ns0="urn://x-www-form-urlencoded/checking/atreceiver/rest">
<client_id>sfv24</client_id>
<client_secret>45g34</client_secret>
<grant_type>doif4</grant_type>
</ns0:MT_x_www_form_urlencoded_REQ>

expecting output : 

client_id=iweu245&client_secret=oirt3453&grant_type=u4wonok64

 

output level field & vlaues seperated by "=" ( equals to ) and seperator : "&"

 

chatgpt xslt code :

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns0="urn://x-www-form-urlencoded/checking/atreceiver/rest">

<xsl:output method="text"/>

<xsl:template match="/">
<xsl:text>client_id=</xsl:text>
<xsl:value-of select="//ns0:MT_x_www_form_urlencoded_REQ/ns0:client_id"/>
<xsl:text>&amp;client_secret=</xsl:text>
<xsl:value-of select="//ns0:MT_x_www_form_urlencoded_REQ/ns0:client_secret"/>
<xsl:text>&amp;grant_type=</xsl:text>
<xsl:value-of select="//ns0:MT_x_www_form_urlencoded_REQ/ns0:grant_type"/>
</xsl:template>

</xsl:stylesheet>

 

chatgpt xslt code output in operation mapping:

nagaraju_cygnet_3-1716962429067.png

 

Thanks in advance.

 

Best Regards,

Nagaraju