I recently came across this requirement where a xsd:datetime in the payload is needed to be converted to a different date time format as follows,

Original format : 2015-01-07T09:30:10+02:00
Required date: 2015/01/07 09:30:10

In WSO2 ESB, I found that this transformation can be achieved through a XSLT mediator, class mediator or a script mediator. In an overview, XSLT mediator uses a XSL stylesheet to format the xml payload passed to the mediator whereas in class mediator and script mediator we use java code and javascript code respectively to manipulate the message context. In this blog post I am going to present how this transformation can be achieved by means of the XSLT mediator.

XSL Stylesheet
<?xml version="1.0" encoding="UTF-8"?>
<localEntry xmlns="http://ws.apache.org/ns/synapse" key="dateTime.xsl">
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">
        <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />
        <xsl:param name="date_time" />
        <xsl:template match="/">
            <dateTime>
                <required>
                    <xsl:value-of select="format-dateTime(xs:dateTime($date_time), '[Y0001]/[M01]/[D01] [H01]:[m01]:[s01] [z]')" />
                </required>
            </dateTime>
        </xsl:template>
    </xsl:stylesheet>
    <description />
</localEntry>


Proxy configuration
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" xmlns:xs="http://www.w3.org/2001/XMLSchema" name="DateTimeTransformation" transports="https http" startOnLoad="true" trace="disable">
    <target>
        <inSequence>
            <property name="originalFormat" expression="$body/dateTime/original" />
            <xslt key="dateTime.xsl">
                <property name="date_time" expression="get-property('originalFormat')" />
            </xslt>
            <log level="full" />
        </inSequence>
    </target>
</proxy>

dateTime.xsl XLS style sheet is stored as an inline xml local entry in ESB.

In the proxy, the original date is passed as an parameter ("date_time") to the XLS style sheet. I have used format-dateTime function, a function of XSL 2.0, to do the transformation.

Sample request
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    <soap:Header />
    <soap:Body>
        <dateTime>
            <original>2015-01-07T09:30:10+02:00</original>
        </dateTime>
    </soap:Body>
</soap:Envelope>

Console output
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    <soap:Body>
        <dateTime xmlns="http://ws.apache.org/ns/synapse" xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <required>2015/01/07 09:30:10 GMT+2</required>
        </dateTime>
    </soap:Body>
</soap:Envelope>
0

Add a comment

Moved to Medium
Moved to Medium
WSO2 Application Server 6.0.0-M2 Released !
WSO2 Application Server 6.0.0-M2 Released !
WSO2 Application Server 6.0.0-M1 Released
WSO2 Application Server 6.0.0-M1 Released
FAD Singapore 2015 - Event Report
Introduction to Go for Java Programmers
Introduction to Go for Java Programmers
WSO2 Carbon Kernel 5.0.0 - Alpha Released !
WSO2 Carbon Kernel 5.0.0 - Alpha Released !
WSO2 Carbon Kernel 5.0.0 - Milestone 06 Released !
WSO2 Carbon Kernel 5.0.0 - Milestone 06 Released !
WSO2 Application Server (WSO2 AS) 5.3.0 Released!
WSO2 Application Server (WSO2 AS) 5.3.0 Released!
How to move a XML element to be the first child of the parent element
How to move a XML element to be the first child of the parent element
/home when moving from Ubuntu to Fedora
/home when moving from Ubuntu to Fedora
Workaround for absolute path issue in SFTP in VFS transport
Workaround for absolute path issue in SFTP in VFS transport
Date time format conversion with XSLT mediator in WSO2 ESB
Date time format conversion with XSLT mediator in WSO2 ESB
WSO2 Carbon Kernel 4.3.0 Released
WSO2 Carbon Kernel 4.3.0 Released
Working with directories that start with '-' in bash
Working with directories that start with '-' in bash
Light Level Meter | Firefox OS App
Mozilla Summit 2013
Electricity Bill Cal | My first app for Firefox OS
6
Keon | It's here :-)
1
PHP Report Maker | A life saver
Mozilla South Asia Inter-Community Meet-up 2013
1
Entering its 3rd year, the latest release : Hanthana Linux 17 (Sithija) is available now!
Entering its 3rd year, the latest release : Hanthana Linux 17 (Sithija) is available now!
FUDCon KL 2012 | Count me in
FUDCon KL 2012 | Count me in
Browse fails to start : FIXED | Sugar 0.96 released
Browse fails to start : FIXED | Sugar 0.96 released
to-doo: a simple to-do list application
to-doo: a simple to-do list application
2
./sugar-jhbuild update: 'BundleModule' has no attribute 'parse_from_xml' [solved]
./sugar-jhbuild update: 'BundleModule' has no attribute 'parse_from_xml' [solved]
Being a Fedora Package Maintainer
Being a Fedora Package Maintainer
1
Hanthana Linux 15 released !
Hanthana Linux 15 released !
Features that impress me on F16 + GNOME 3.2
2
t2u
t2u
1
Accepted
1
Matrix and SFD
Matrix and SFD
Empathy log
Empathy log
3
Dropbox usage made easy in nautilus
5
OpenOffice.org Translation Marathon 2010 April
Touchpad in GDM
Touchpad in GDM
Airtel GPRS with E-tel P7 in Fedora 11
Airtel GPRS with E-tel P7 in Fedora 11
Acer Aspire 4736z with Fedora 11
3
purple-microblog to Gwitter
purple-microblog to Gwitter
Twitter, Facebook and Pidgin
Twitter, Facebook and Pidgin
1
Watch videos in linux terminal
Watch videos in linux terminal
2
Online Java Compiler
Online Java Compiler
CDPATH
CDPATH
Wine matures.....
Wine matures.....
BlockSite
BlockSite
Convert
Convert
Shifted to Fedora from Ubuntu
Shifted to Fedora from Ubuntu
Budget SMS from Dialog
Budget SMS from Dialog
gSMS
gSMS
ScribeFire
ScribeFire
1
FOSS event @ Galle
FOSS event @ Galle
Pidgin + Facebook chat
Pidgin + Facebook chat
Cloud computing
Cloud computing
Java Calculator for Mobile Phones
Java Calculator for Mobile Phones
2
How to configure ZXDSL 852 ADSL Modem (Modem given free with the SLT ADSL connection)
How to configure ZXDSL 852 ADSL Modem (Modem given free with the SLT ADSL connection)
A simple java applet ..........
A simple java applet ..........
2007 A/L @ RCG
2007 A/L @ RCG
ආලකමන්දා .....
ආලකමන්දා .....
Send free SMSs with Suntel .....
Send free SMSs with Suntel .....
පළමු සිංහල වියුණු සටහන
පළමු සිංහල වියුණු සටහන
1
A simple JAVA application for mobile phones ....
A simple JAVA application for mobile phones ....
SLT ADSL Configuration
SLT ADSL Configuration
20
How to configure java in windows environment
How to configure java in windows environment
5
Suntel and Lanka Bell CDMA Phones supported in Ubuntu
Suntel and Lanka Bell CDMA Phones supported in Ubuntu
11
Calendar.srilanka
Calendar.srilanka
Make money from your site
Make money from your site
"Island Spell" by Wendy Whatmore
"Island Spell" by Wendy Whatmore
9
NetBeans
NetBeans
Mercury CyberPix E-580V Digital Camera and a Nokia 6030 phone for sale .....
Mercury CyberPix E-580V Digital Camera and a Nokia 6030 phone for sale .....
The Snare by James Stephens
The Snare by James Stephens
9
Difference
Difference
Pause
Pause
Welcome
Welcome
About Me
About Me
Subscribe
Subscribe
Popular Posts
Popular Posts
  • "The Snare is a poem which evokes positive attitudes within the reader." (1) Which kind of attitudes are evoked? (2) Show them wit...
  • "Island Spell" by Wendy Whatmore vividly describes a beautiful island. The starts her poem saying that she was caught in an island...
  • Try configuring your SLT ADSL connection yourself. Don't WASTE money for SLT . Here are the settings. Type : PPP...
  • To use java tools (javac, java, applet viewer etc.) from anywhere in the dos prompt java should be configured. Suppose that you have already...
  • A late announcement, a little more than 2 years, I moved to Medium. I won't be making any new posts here in this blog. Please refer/foll...
  • SOURCE: http://www.avidtrader.com/wordpress/wp-content/uploads/2013/01/reports.jpg Recently I was involved in developing a registration...
  • Welcome to WSO2 Application Server 6.0.0, the successor of WSO2 Carbon based Application Server. WSO2 Application Server 6.0.0 is a complet...
  • I recently came across this requirement where a  xsd:datetime  in the payload is needed to be converted to a different date time format as ...
  • Dialog GSM offers its latest service,Budget SMS, to both post paid and pre paid customers. With this service you will be able to send D2D SM...
  • Photo Credit : Prima Yogi FAD Singapore 2015 was held on 5th and 6th of December in Singapore and I participated at the event. FAD (F...
Labels
My Links
Blogs I read
Blogs I read
Loading