XSLT code for change the date format..

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <doc> <newdate> <xsl:call-template name="FormatDate"> <xsl:with-param name="DateTime" select="doc/longdate" /> </xsl:call-template> </newdate> </doc> </xsl:template> <xsl:template name="FormatDate"> <xsl:param name="DateTime" /> <!-- new date format 2006-01-14T08:55:22 29-Nov-2017 03:26:48--> <xsl:variable name="mo-temp"> <xsl:value-of select="substring-after($DateTime,'-')" /> </xsl:variable> <xsl:variable name="mo"> <xsl:value-of select="substring-before($mo-temp,'-')" /> </xsl:variable> <xsl:variable name="day-temp"> <xsl:value-of select="substring-after($DateTime,'-')" /> </xsl:variable> <xsl:variable name="day"> <xsl:value-of select="substring-before($DateTime, '-')" /> </xsl:variable> <xsl:variable name="year-temp0"> <xsl:value-of select="substring-after($DateTime,$mo)" disable-output-escaping="no" /> </xsl:variable> <xsl:variable name="year-temp"> <xsl:value-of select="substring-after($year-temp0,'-')" /> </xsl:variable> <xsl:variable name="year"> <xsl:value-of select="substring-before($year-temp,' ')" /> </xsl:variable> <xsl:variable name="time"> <xsl:value-of select="substring-after($year-temp,' ')" /> </xsl:variable> <xsl:variable name="hh"> <xsl:value-of select="substring-after($time,':')" /> </xsl:variable> <xsl:variable name="mm-temp"> <xsl:value-of select="substring-after($time,':')" /> </xsl:variable> <xsl:variable name="mm"> <xsl:value-of select="substring-before($time,':')" /> </xsl:variable> <xsl:variable name="ss"> <xsl:value-of select="substring-after($mm-temp,':')" /> </xsl:variable> <xsl:value-of select="$year" /> <xsl:value-of select="'-'" /> <xsl:choose> <xsl:when test="$mo = 'Jan'">01</xsl:when> <xsl:when test="$mo = 'Feb'">02</xsl:when> <xsl:when test="$mo = 'Mar'">03</xsl:when> <xsl:when test="$mo = 'Apr'">04</xsl:when> <xsl:when test="$mo = 'May'">05</xsl:when> <xsl:when test="$mo = 'Jun'">06</xsl:when> <xsl:when test="$mo = 'Jul'">07</xsl:when> <xsl:when test="$mo = 'Aug'">08</xsl:when> <xsl:when test="$mo = 'Sep'">09</xsl:when> <xsl:when test="$mo = 'Oct'">10</xsl:when> <xsl:when test="$mo = 'Nov'">11</xsl:when> <xsl:when test="$mo = 'Dec'">12</xsl:when> </xsl:choose> <xsl:value-of select="'-'" /> <xsl:if test="(string-length($day) < 2)"> <xsl:value-of select="0" /> </xsl:if> <xsl:value-of select="$day" /> <xsl:value-of select="' '" disable-output-escaping="no" /> <xsl:value-of select="$hh" /> <xsl:value-of select="':'" /> <xsl:value-of select="$mm" /> <xsl:value-of select="':'" /> <xsl:value-of select="$ss" /> </xsl:template> </xsl:stylesheet>
It will convert the format "29-Nov-2017 03:26:48" to "2017-11-29 26:48:03:48"

#INPUT XML :-

<doc>
<longdate>29-Nov-2017 03:26:48</longdate>
</doc>

#OUTPUT XML:-

<doc>
<newdate>2017-11-29 26:48:03:48</newdate>
</doc>

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.