Reputation: 391
The request I receive contains dates in the following format:
<CreatedDate>08/24/2014 21:53:14</CreatedDate>
I need to convert the value into YYYY-MM-DD format using xslt. I can identify all "target" nodes by a certain naming pattern (they all are called somethingDate). Is there any ready-to-use syntax/function?
Upvotes: 0
Views: 644
Reputation: 117165
If you need to do this for several nodes in your input, you'd better use a named template (or a function, if you're using XSLT 2.0), for example:
<xsl:template name="formatDate">
<xsl:param name="mmddyyyy"/>
<xsl:value-of select="substring($mmddyyyy, 7, 4)"/>
<xsl:text>-</xsl:text>
<xsl:value-of select="substring($mmddyyyy, 1, 2)"/>
<xsl:text>-</xsl:text>
<xsl:value-of select="substring($mmddyyyy, 4, 2)"/>
</xsl:template>
Upvotes: 1