[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How to get UTC displayed on XSLT

Subject: Re: How to get UTC displayed on XSLT
From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx>
Date: Tue, 23 Aug 2005 23:02:24 +0530
xsl time zone
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.