Thursday, 24 January 2019

Create a piece of XSLT that will take a date in the US date format M/D/YYYY and convert it to the standard date format YYYY-MM-DD

Create a piece of XSLT that will take a date in the US date format M/D/YYYY and convert it to the standard date format YYYY-MM-DD. The date 9/4/2001 should get converted to 2001-09-04?

Answer:


<xsl:template match="date"> <xsl:variable name="M" select="substring-before(., '/')" /> <xsl:variable name="D" select="substring-before(substring-after(., '/'), '/')" /> <xsl:variable name="Y" select="substring-after(substring-after(., '/'), '/')" /> <xsl:value-of select="concat($Y, '-', format-number($M, '00'), '-', format-number($D, '00'))" /> <br /> </xsl:template>

No comments:

Post a Comment