Wednesday, November 13, 2019

12c SOA - Use of call template

Call template is usually called named templates to the XSLT map. These templates can be edited within the XSLT Map Editor. We can invoke named templates by using the xsl:call-template instruction.

Use case:
Here I will show you how to get the time Zone Hour AM PM as "9:00AM" from the input as orientationStartDateTime "2019-11-11T09:00:00" using the call template.

Create a SOA Project

 Select composite with BPEL Process
 Select Synchronous BPEL Process
 Modify the schema
 <?xml version="1.0" encoding="UTF-8"?>
<schema attributeFormDefault="unqualified"
                elementFormDefault="qualified" targetNamespace="http://xmlns.oracle.com/SOAApplication/Project1/CallTemplateBPELProcess"
                xmlns="http://www.w3.org/2001/XMLSchema">
                <element name="process">
                                <complexType>
                                                <sequence>
                                                                <element name="orientationStartDateTime" type="string"/>
                                                </sequence>
                                </complexType>
                </element>
                <element name="processResponse">
                                <complexType>
                                                <sequence>
                                                                <element name="timeZoneHourAMPM" type="string"/>
                                                </sequence>
                                </complexType>
                </element>
</schema>
 Drag and drop a Transformation activity from Components pallet
 Select the source and Target payloads
 Open the XSLT
 Add the call template

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:ns0="http://xmlns.oracle.com/SOAApplication/Project1/CallTemplateBPELProcess"
                xmlns:socket="http://www.oracle.com/XSL/Transform/java/oracle.tip.adapter.socket.ProtocolTranslator"
                xmlns:oracle-xsl-mapper="http://www.oracle.com/xsl/mapper/schemas"
                xmlns:dvm="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue"
                xmlns:mhdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.mediator.service.common.functions.MediatorExtnFunction"
                xmlns:oraxsl="http://www.oracle.com/XSL/Transform/java"
                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:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions"
                exclude-result-prefixes="oracle-xsl-mapper xsi xsd xsl ns0 socket dvm mhdr oraxsl oraext xp20 xref"
                xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype"
                xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <oracle-xsl-mapper:schema>
    <!--SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY.-->
    <oracle-xsl-mapper:mapSources>
      <oracle-xsl-mapper:source type="WSDL">
        <oracle-xsl-mapper:schema location="../WSDLs/CallTemplateBPELProcess.wsdl"/>
        <oracle-xsl-mapper:rootElement name="process"
                                       namespace="http://xmlns.oracle.com/SOAApplication/Project1/CallTemplateBPELProcess"/>
      </oracle-xsl-mapper:source>
    </oracle-xsl-mapper:mapSources>
    <oracle-xsl-mapper:mapTargets>
      <oracle-xsl-mapper:target type="WSDL">
        <oracle-xsl-mapper:schema location="../WSDLs/CallTemplateBPELProcess.wsdl"/>
        <oracle-xsl-mapper:rootElement name="processResponse"
                                       namespace="http://xmlns.oracle.com/SOAApplication/Project1/CallTemplateBPELProcess"/>
      </oracle-xsl-mapper:target>
    </oracle-xsl-mapper:mapTargets>
    <!--GENERATED BY ORACLE XSL MAPPER 12.2.1.0.0(XSLT Build 151013.0700.0085) AT [WED NOV 13 11:17:16 IST 2019].-->
  </oracle-xsl-mapper:schema>
  <!--User Editing allowed BELOW this line - DO NOT DELETE THIS LINE-->
  <xsl:template match="/">
    <xsl:variable name="orientationStartDateTime" select="/ns0:process/ns0:orientationStartDateTime"/>
    <xsl:variable name="hour" select="xp20:hours-from-dateTime($orientationStartDateTime)"/>
    <xsl:variable name="amPm"
                  select="substring(xp20:format-dateTime($orientationStartDateTime, '[D] [MNn] [Y] [h]:[m01][PN,*-2]'),string-length(xp20:format-dateTime($orientationStartDateTime, '[D] [MNn] [Y] [h]:[m01][PN,*-2]'))-1)"/>
    <ns0:processResponse>
      <xsl:variable name="timeZoneHourAMPM">
<!-- Call template -->
        <xsl:call-template name="timeZoneHour">
          <xsl:with-param name="hour" select="$hour"/>
          <xsl:with-param name="startDateTime" select="$orientationStartDateTime"/>
          <xsl:with-param name="amPm" select="$amPm"/>
        </xsl:call-template>
      </xsl:variable>
      <ns0:timeZoneHourAMPM>
        <xsl:value-of select="$timeZoneHourAMPM"/>
      </ns0:timeZoneHourAMPM>
    </ns0:processResponse>
  </xsl:template>
<!--Called template definition-->
  <xsl:template name="timeZoneHour">
    <xsl:param name="hour"/>
    <xsl:param name="startDateTime"/>
    <xsl:param name="amPm"/>
    <xsl:variable name="minutes">
      <xsl:choose>
        <xsl:when test="xp20:minutes-from-dateTime($startDateTime) &lt; 10">
          <xsl:value-of select="concat(xp20:minutes-from-dateTime($startDateTime),'0')"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="xp20:minutes-from-dateTime($startDateTime)"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="$hour > 12">
        <xsl:value-of select="concat($hour -12,':',$minutes,'PM')"/>
      </xsl:when>
      <xsl:when test="$hour = 0">
        <xsl:value-of select="concat(12,':',$minutes,'AM')"/>
      </xsl:when>
      <xsl:when test="$hour &lt; 0">
        <xsl:value-of select="concat($hour + 12,':',$minutes,'PM')"/>
      </xsl:when>
      <xsl:when test="$hour &lt; 12">
        <xsl:value-of select="concat($hour ,':',$minutes,'AM')"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="concat($hour,':',$minutes,$amPm)"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>

Deploy and test from EM console


Another call template sample code to get the following date format from Datetime format.
Input: orientationStartDateTime "2019-11-11T09:00:00
Output: Date: Monday, November 11th, 2019

Call Template:
<xsl:call-template name="date-format">
<xsl:with-param name="yyyy-mm-dd" select="concat(xp20:year-from-dateTime($OrientationStartDateTime),'-',xp20:month-from-dateTime($OrientationStartDateTime),'-',xp20:day-from-dateTime($OrientationStartDateTime))"/>
</xsl:call-template>
Called template:
<xsl:template name="date-format">
      <xsl:param name="yyyy-mm-dd"/>
      <xsl:variable name="yyyy" select="substring-before($yyyy-mm-dd, '-')"/>
      <xsl:variable name="mm-dd" select="substring-after($yyyy-mm-dd, '-')"/>
      <xsl:variable name="mm" select="substring-before($mm-dd, '-')"/>
      <xsl:variable name="dd" select="substring-after($mm-dd, '-')"/>
      <xsl:variable name="Y">
         <xsl:choose>
            <xsl:when test="$mm &lt; 3">
               <xsl:value-of select="$yyyy - 1"/>
            </xsl:when>
            <xsl:otherwise>
               <xsl:value-of select="$yyyy + 0"/>
            </xsl:otherwise>
         </xsl:choose>
      </xsl:variable>
      <xsl:variable name="y" select="$Y mod 100"/>
      <xsl:variable name="c" select="floor($Y div 100)"/>
      <xsl:variable name="d" select="$dd+0"/>
      <xsl:variable name="m">
         <xsl:choose>
            <xsl:when test="$mm &lt; 3">
               <xsl:value-of select="$mm + 12"/>
            </xsl:when>
            <xsl:otherwise>
               <xsl:value-of select="$mm + 0"/>
            </xsl:otherwise>
         </xsl:choose>
      </xsl:variable>
      <xsl:variable name="w" select="(($d + floor(($m + 1) * 2.6) + $y + floor($y div 4) + floor($c div 4) - $c * 2 - 1)+70) mod 7"/>
      <xsl:variable name="www">
         <xsl:choose>
            <xsl:when test="$w = 0">Sunday</xsl:when>
            <xsl:when test="$w = 1">Monday</xsl:when>
            <xsl:when test="$w = 2">Tuesday</xsl:when>
            <xsl:when test="$w = 3">Wednesday</xsl:when>
            <xsl:when test="$w = 4">Thursday</xsl:when>
            <xsl:when test="$w = 5">Friday</xsl:when>
            <xsl:when test="$w = 6">Saturday</xsl:when>
         </xsl:choose>
      </xsl:variable>
      <xsl:variable name="mmm">
         <xsl:choose>
            <xsl:when test="$mm =  1">January</xsl:when>
            <xsl:when test="$mm =  2">February</xsl:when>
            <xsl:when test="$mm =  3">March</xsl:when>
            <xsl:when test="$mm =  4">April</xsl:when>
            <xsl:when test="$mm =  5">May</xsl:when>
            <xsl:when test="$mm =  6">June</xsl:when>
            <xsl:when test="$mm =  7">July</xsl:when>
            <xsl:when test="$mm =  8">August</xsl:when>
            <xsl:when test="$mm =  9">September</xsl:when>
            <xsl:when test="$mm = 10">October</xsl:when>
            <xsl:when test="$mm = 11">November</xsl:when>
            <xsl:when test="$mm = 12">December</xsl:when>
         </xsl:choose>
      </xsl:variable>
      <xsl:variable name="th">
         <xsl:choose>
            <xsl:when test="$dd = 1">st</xsl:when>
            <xsl:when test="$dd = 21">st</xsl:when>
            <xsl:when test="$dd = 31">st</xsl:when>
            <xsl:when test="$dd = 2">nd</xsl:when>
            <xsl:when test="$dd = 22">nd</xsl:when>
            <xsl:when test="$dd = 3">rd</xsl:when>
            <xsl:when test="$dd = 23">rd</xsl:when>
            <xsl:otherwise>th</xsl:otherwise>
         </xsl:choose>
      </xsl:variable>
      <xsl:value-of select="concat($www, ', ', $mmm, ' ', $d,$th,', ',$yyyy)"/>
   </xsl:template>

No comments:

Post a Comment

Featured Post

11g to 12c OSB projects migration points

1. Export 11g OSB code and import in 12c Jdeveloper. Steps to import OSB project in Jdeveloper:   File⇾Import⇾Service Bus Resources⇾ Se...