Subject: Re: [xsl] How to get UTC displayed on XSLT From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx> Date: Tue, 23 Aug 2005 23:02:24 +0530 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] How to get UTC displayed on X, Meena Nanjundeswar | Thread | Re: [xsl] How to get UTC displayed , Mukul Gandhi |
Re: [xsl] Creation of DTD, Wendell Piez | Date | Re: [xsl] How to convert day-of-mon, Manfred Staudinger |
Month |