Oracle SOA Suite Online Training

Interested in learning Oracle SOA Suite 12c?
Learn from the author of this blog!
A complete and comprehensive course on the #1 platform on SOA - Oracle SOA Suite

Click here to find the complete course details
Click here to check the first session on Oracle SOA Suite 12c

================================================================================================

XSL for splitting CSV into seperate nodes

Input

<varForCSVComplexType>
 <IndActivityPayload xmlns="http://www.example.org">
  <PlannedFinishDate/>
  <AttachmentLoc>406,405,401</AttachmentLoc>
  <reviewerApproval/>
  <reviewerComments/>
 </IndActivityPayload>
</varForCSVComplexType>

Required Output

<ArrayOfUCMDocIds xmlns:ns0="http://www.example.org" xmlns="http://www.example.org">
<ns0:indDocId>406</ns0:indDocId>
<ns0:indDocId>405</ns0:indDocId>
<ns0:indDocId>401</ns0:indDocId>
</ArrayOfUCMDocIds

XSLT : Kind of recurrent call till there are no comma(',')

<xsl:stylesheet version="1.0"
                xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
                xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
                xmlns:mhdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.mediator.service.common.functions.MediatorExtnFunction"
                xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
                xmlns:oraext="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:ns0="http://www.example.org"
                xmlns:dvm="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue"
                xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:med="http://schemas.oracle.com/mediator/xpath"
                xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath"
                xmlns:bpm="http://xmlns.oracle.com/bpmn20/extensions"
                xmlns:xdk="http://schemas.oracle.com/bpel/extension/xpath/function/xdk"
                xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:bpmn="http://schemas.oracle.com/bpm/xpath"
                xmlns:ora="http://schemas.oracle.com/xpath/extension"
                xmlns:socket="http://www.oracle.com/XSL/Transform/java/oracle.tip.adapter.socket.ProtocolTranslator"
                xmlns:ldap="http://schemas.oracle.com/xpath/extension/ldap"
                exclude-result-prefixes="xsi xsl ns0 xsd bpws xp20 mhdr bpel oraext dvm hwf med ids bpm xdk xref bpmn ora socket ldap">

 <xsl:strip-space elements="*"/>
 <xsl:template match="/ns0:IndActivityPayload/ns0:AttachmentLoc">
  <ns0:IndActivityPayload>
    <xsl:apply-templates/>
  </ns0:IndActivityPayload>
 </xsl:template>

 <xsl:template match="text()" name="split">
  <xsl:param name="pText" select="."/>
  <xsl:param name="pItemElementName" select="'ns0:AttachmentLoc'"/>
 
    <xsl:if test="string-length($pText) > 0">
     <!-- Below declaration basically concatenates a ',' to the value just in case we have only one element and if there is no comma, then the value just returns nothing -->
     <xsl:variable name="vNextItem" select="substring-before(concat($pText, ','), ',')"/>
     <ns0:indDocId>
        <xsl:value-of select="$vNextItem"/>
      </ns0:indDocId>
      <xsl:call-template name="split">
        <xsl:with-param name="pText" select="substring-after($pText, ',')"/>
        <xsl:with-param name="pItemElementName" select="$pItemElementName"/>
      </xsl:call-template>
    </xsl:if>
 </xsl:template>
</xsl:stylesheet>

No comments:

Post a Comment