|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: How to get UTC displayed on XSLT
Here is a XSLT 2.0 solution tested with Saxon 8.4
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xyz="http://utc"
version="2.0">
<xsl:output method="text" />
<xsl:template match="/">
UTC time(hh:mm:ss) - <xsl:value-of
select="xyz:UtcTime(xs:string(current-time()))" />
</xsl:template>
<xsl:function name="xyz:UtcTime">
<xsl:param name="curr-time" as="xs:string"/>
<xsl:choose>
<xsl:when test="contains($curr-time,'+')">
<xsl:variable name="local-time"
select="substring-before($curr-time,'+')" />
<xsl:variable name="time-zone"
select="substring-after($curr-time,'+')" />
<xsl:variable name="x" select="substring-before($local-time,':')" />
<xsl:variable name="y"
select="substring-before(substring-after($local-time,':'),':')" />
<xsl:variable name="z"
select="substring-after(substring-after($local-time,':'),':')" />
<xsl:variable name="sec1" select="(xs:integer($x) * 60 * 60) +
(xs:integer($y) * 60) + xs:float($z)" />
<xsl:variable name="u" select="substring-before($time-zone,':')" />
<xsl:variable name="v" select="substring-after($time-zone,':')" />
<xsl:variable name="sec2" select="(xs:integer($u) * 60 * 60) +
(xs:integer($v) * 60)" />
<xsl:variable name="sec3" select="$sec1 - $sec2" />
<xsl:value-of select="floor(($sec3 div 60) div 60)"
/>:<xsl:value-of select="floor(($sec3 div 60) mod 60)"
/>:<xsl:value-of select="$sec3 - ((floor(($sec3 div 60) div 60) * 60 *
60) + (floor(($sec3 div 60) mod 60) * 60))" />
</xsl:when>
<xsl:when test="contains($curr-time,'-')">
<xsl:variable name="local-time"
select="substring-before($curr-time,'-')" />
<xsl:variable name="time-zone"
select="substring-after($curr-time,'-')" />
<xsl:variable name="x" select="substring-before($local-time,':')" />
<xsl:variable name="y"
select="substring-before(substring-after($local-time,':'),':')" />
<xsl:variable name="z"
select="substring-after(substring-after($local-time,':'),':')" />
<xsl:variable name="sec1" select="(xs:integer($x) * 60 * 60) +
(xs:integer($y) * 60) + xs:float($z)" />
<xsl:variable name="u" select="substring-before($time-zone,':')" />
<xsl:variable name="v" select="substring-after($time-zone,':')" />
<xsl:variable name="sec2" select="(xs:integer($u) * 60 * 60) +
(xs:integer($v) * 60)" />
<xsl:variable name="sec3" select="$sec1 + $sec2" />
<xsl:value-of select="floor(($sec3 div 60) div 60)"
/>:<xsl:value-of select="floor(($sec3 div 60) mod 60)"
/>:<xsl:value-of select="$sec3 - ((floor(($sec3 div 60) div 60) * 60 *
60) + (floor(($sec3 div 60) mod 60) * 60))" />
</xsl:when>
</xsl:choose>
</xsl:function>
</xsl:stylesheet>
Regards,
Mukul
On 8/23/05, Meena Nanjundeswar <meenasargur@xxxxxxxxx> wrote:
> Hi List:
>
> I need to display time in UTC on my stylesheet. Any suggestions?
>
> Thank you in advance
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








