Reputation: 47
I have a date string in format YYYYMMDD for example 20140330 In xsl 1.0 I want to convert the date string to format YYYY-MM-DD for example 2014-03-30
I tried using several date functions but it did not work. Can anyone help me to convert the date ?
Upvotes: 3
Views: 10440
Reputation: 7173
You can use the substring function. Given the following input XML:
<root>20140330</root>
and the following stylesheet:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="root">
<xsl:value-of select="concat(substring(., 1, 4), '-', substring(., 5, 2), '-', substring(., 7, 2))"/>
</xsl:template>
</xsl:stylesheet>
it outputs:
2014-03-30
Upvotes: 6