Skip to Content

How use XSLT mapping to format date

Hi Integration Experts,

I need to convert a date in this format

2018-04-13T12:42:42.224416+00:00 to ddMMyyHHmmss based on the substrings of the original date value by using XSLT mapping. How I can achieve this?

Input:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<order>
<id>123</id>
<create_date>2018-01-01T12:00:00.224416+00:00</create_date>
</order>
</root>

output:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<order>
<id>123</id>
<create_date>20180101120000</create_date>
</order>
</root>

Have a nice weekend!

Regards,

Jeremy

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Apr 14 at 05:04 AM

    Hello Jeremy,

    Below will convert the same.

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output method="xml" indent="yes"/>
    
    	<xsl:template match="@* | node()">
    		<xsl:copy>
    			<xsl:apply-templates select="@* | node()"/>
    		</xsl:copy>
    	</xsl:template>
    
    	<xsl:template match="create_date">
    		<create_date>
    			<xsl:value-of select="format-dateTime(.,'[Y0001][M01][D01][H01][m01][s01]')" />
    		</create_date>
    	</xsl:template>
    
    </xsl:stylesheet>
    

    Regards,

    Sriprasad Shivaram Bhat

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 16 at 02:10 AM

    Hello Sriprasad Shivaram Bhat,

    Thanks this works!

    Regards,

    Jeremy

    Add comment
    10|10000 characters needed characters exceeded