Monday, April 10, 2023

Convert String to List based on a delimiter in OIC

Many of my colleagues have reached out to me for a solution to a scenario where the Downstream app expects List of values as Response and Upstream app is sending data as comma separated value.

For example, Upstream Data format - 


And Downstream is expecting as-


Solution for this is simple. Use Xpath function oraext:create-nodeset-from-delimited-string

The function takes a delimited string and returns a nodeSet and has the following signature:
oraext:create-nodeset-from-delimited-string(qname, delimited-string, delimiter)
where –
qname – is name of node which will hold Nodeset values. Example (“ns0:listValue”)
delimited-string – String containing delimited values. Example (“aaa,bbb,ccc”)
delimiter – delimiter value. Example (“,”)


Let’s implement this in a sample App Driven Orchestration OIC Service –

1. Create App Driven Orchestration service and configure Rest Endpoint with Request and Response Payload as mentioned above

2. Map CityList -> City and now we will move to Source code of Map and make changes

3. Add a variable “varCityList” which will hold nodes from Create Nodeset function

<xsl:variable name="varCityList" select="oraext:create-nodeset-from-delimited-string('city',/nstrgmpr:execute/nstrgdfl:request-wrapper/nstrgdfl:CityList, ',' )"/>

4. Add for each element inside varCityList above City as we want City to repeat for every element and then in City select value of current element

Finally, your map would look like this -

<xsl:template match="/" xml:id="id_11">
<nstrgmpr:executeResponse xml:id="id_12">
<nstrgdfl:response-wrapper>
<xsl:variable name="varCityList">
<xsl:copy-of select="oraext:create-nodeset-from-delimited-string('city',/nstrgmpr:execute/nstrgdfl:request-wrapper/nstrgdfl:CityList, ',' )"/>
</xsl:variable>
<xsl:for-each select="$varCityList/*">
<nstrgdfl:City>
<xsl:value-of select="."/>
</nstrgdfl:City>
</xsl:for-each>
</nstrgdfl:response-wrapper>
</nstrgmpr:executeResponse>
</xsl:template>

Now, you can Save, Activate and test the integration. 

Thank you.