Thursday, June 11, 2020

SOA 12c - Call Template to get a date format

Here we will see how to use template to get following date format.

Input:
 <HIRE_DATE>30-JAN-2012</HIRE_DATE>
Output:
 <HIRE_DATE>2012-01-30</HIRE_DATE>

In the XSLT :

In the main template use:
 <ns1:hireDate>
    <xsl:call-template name="formatDate">
        <xsl:with-param name="date" select="HIRE_DATE"/>
    </xsl:call-template>
  </ns1:hireDate>

Called template:
<xsl:template name="formatDate">
      <xsl:param name="date"/>
      <xsl:variable name="year" select="substring($date, 8, 4)"/>
      <xsl:variable name="month" select="substring($date, 4, 3)"/>
      <xsl:variable name="day" select="substring($date, 1, 2)"/>
      <xsl:choose>
         <xsl:when test="$month='JAN'">
            <xsl:value-of select="concat($year,'-01-',$day)"/>
         </xsl:when>
         <xsl:when test="$month='FEB'">
            <xsl:value-of select="concat($year,'-02-',$day)"/>
         </xsl:when>
         <xsl:when test="$month='MAR'">
            <xsl:value-of select="concat($year,'-03-',$day)"/>
         </xsl:when>
         <xsl:when test="$month='APR'">
            <xsl:value-of select="concat($year,'-04-',$day)"/>
         </xsl:when>
         <xsl:when test="$month='MAY'">
            <xsl:value-of select="concat($year,'-05-',$day)"/>
         </xsl:when>
         <xsl:when test="$month='JUN'">
            <xsl:value-of select="concat($year,'-06-',$day)"/>
         </xsl:when>
         <xsl:when test="$month='JUL'">
            <xsl:value-of select="concat($year,'-07-',$day)"/>
         </xsl:when>
         <xsl:when test="$month='AUG'">
            <xsl:value-of select="concat($year,'-08-',$day)"/>
         </xsl:when>
         <xsl:when test="$month='SEP'">
            <xsl:value-of select="concat($year,'-09-',$day)"/>
         </xsl:when>
         <xsl:when test="$month='OCT'">
            <xsl:value-of select="concat($year,'-10-',$day)"/>
         </xsl:when>
         <xsl:when test="$month='NOV'">
            <xsl:value-of select="concat($year,'-11-',$day)"/>
         </xsl:when>
         <xsl:when test="$month='DEC'">
            <xsl:value-of select="concat($year,'-12-',$day)"/>
         </xsl:when>
      </xsl:choose>
   </xsl:template>

No comments:

Post a Comment

Featured Post

OIC - How to Send Email Using Twilio SendGrid API in Oracle Integration Cloud (OIC)

How to Send Email Using Twilio SendGrid API in Oracle Integration Cloud (OIC) Use Case You want to send transactional or notification emai...