How can I format the below XML date element in XSLT version1.0 ? The GenerationTime
has to be formatted in pattern yyyy-MM-dd'T'HH:mm:ss
in the output XML.
<Values>
<value name="GenerationTime">Tue Dec 29 14:32:53 UTC 2020</value>
<Values>
Here is what I found from my product's (Intergation Server) documentation
When executed, the XSLT service calls an external XSLT engine to convert the XML data. The external XSLT engine must be Java API for XML Processing (JAXP)-compatible. By default, Integration Server includes the Xerces parser and the Xalan XSLT style sheet processor from the Apache Software Foundation.
Xalan supports the EXSLT str:tokenize() extension function, so you could do something like:
<xsl:template name="reformat-date">
<xsl:param name="input"/>
<!-- extract dateTime components -->
<xsl:variable name="tokens" select="str:tokenize($input, ' ')"/>
<xsl:variable name="mmm" select="$tokens[2]"/>
<xsl:variable name="day" select="$tokens[3]"/>
<xsl:variable name="time" select="$tokens[4]"/>
<xsl:variable name="year" select="$tokens[6]"/>
<!-- convert MMM to month number -->
<xsl:variable name="month" select="string-length(substring-before('JanFebMarAprMayJunJulAugSepOctNovDec', $mmm)) div 3 + 1" />
<!-- output -->
<xsl:value-of select="$year"/>
<xsl:value-of select="format-number($month, '-00')"/>
<xsl:value-of select="format-number($day, '-00')"/>
<xsl:text>T</xsl:text>
<xsl:value-of select="$time"/>
</xsl:template>