I have to convert this GMT format to EST in xslt 1.0.
<Date>Mon, 11 Aug 2009 13:15:10 GMT</Date>
is there any of doing that?
I have to convert this GMT format to EST in xslt 1.0.
<Date>Mon, 11 Aug 2009 13:15:10 GMT</Date>
is there any of doing that?
Here is a pure XSLT solution:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:my="my:my" >
<xsl:import href=
"C:\Program Files\Marrowsoft\Xselerator25\Samples\Libraries\datetime_lib.xsl"/>
<xsl:output method="text"/>
<xsl:param name="pnewZone" select="'EST'"/>
<my:zones>
<zone name="GMT" offset="+00:00"/>
<zone name="EST" offset="-05:00"/>
</my:zones>
<xsl:template match="/">
<xsl:variable name="vDay" select=
"substring-before(substring-after(., ' '), ' ')
"/>
<xsl:variable name="vMonthName" select=
"substring-before(substring-after(., concat($vDay, ' ')), ' ')
"/>
<xsl:variable name="vYear" select=
"substring-before(substring-after(., concat($vMonthName, ' ')), ' ')
"/>
<xsl:variable name="vTime" select=
"substring-before(substring-after(., concat($vYear, ' ')), ' ')
"/>
<xsl:variable name="vMonth" select=
"substring-before(
substring($default-month-names,
string-length(substring-before($default-month-names,
$vMonthName)
)-2),
']'
)
"/>
<xsl:variable name="vZone"
select="substring-after(., concat($vTime, ' '))"/>
<xsl:variable name="vzoneOffset" select=
"document('')/*/my:zones/*[@name=$vZone]/@offset"/>
<xsl:variable name="vnewzoneOffset" select=
"document('')/*/my:zones/*[@name=$pnewZone]/@offset"/>
<xsl:variable name="vDateTimeUTC" select=
"concat($vYear, '-', $vMonth, '-', $vDay, 'T', $vTime, 'Z', $vzoneOffset)"/>
<xsl:call-template name="local-to-local">
<xsl:with-param name="datetime" select="$vDateTimeUTC"/>
<xsl:with-param name="local-offset" select="$vnewzoneOffset"/>
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>
when this transformation is applied on the provided XML document:
<Date>Mon, 11 Aug 2009 13:15:10 GMT</Date>
the desired, correct result is produced:
2009-08-11T08:15:10Z-05:00
Do note:
I am using the datetime_lib.xsl
template library of Martin Rowlinson. This library is part of the XSelerator, which at present is a free product and can be downloaded at SourceForge.
All processing in the above code is to prepare the parameters to the local-to-local
template from the imported library.
I found a bug in local-to-local
and corrected it. Replace on line 1143 the following:
<xsl:when test="($offset != 0) and ($new-offset != 0)">
with
<xsl:when test="($offset != 0) or ($new-offset != 0)">