XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
gary comstockSubject: use javascript to get client time zone offset
Author: gary comstock
Date: 14 Feb 2007 03:19 PM
We have a web service that returns an MS Exchange servers free/busy schedule for a specified user. The problem is that while applying the xslt stylesheeet I need to know the browser clients time zone to know what postion() to start. I discovered the java date object but apparantly this is the server date. Everything would work fine if I could just execute this piece of javascript and use the output as $gmtoffset:

function GetClientUTC()
{
var now = new Date();
var offset = (now.getTimezoneOffset() / 60)*-1;
return offset;
}

Can someone give me some direction on achieving this?

Here's what I have so far:

<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="java:java.util.Date"
exclude-result-prefixes="date"
version="1.0">
<xsl:variable name="dt" select="date:new()"/>
<xsl:variable name="offset" select="date:getTimezoneOffset($dt)"/>
<xsl:variable name="gmtoffset"><xsl:value-of select="number($offset) div 60 * -1"/></xsl:variable>
<!--if gmt minus something-->
<xsl:if test="contains($gmtoffset,'-')">
<xsl:variable name="val" select="number(substring($gmtoffset,2,2))"/>
<!--gmt + 2 * 4 (15 minute increments)-->
<xsl:variable name="start" select="number(($val+2)*4)"/>
<xsl:variable name="end" select="number($start+36)"/>
</xsl:if>

Here are some values of my results.xml

<Field name="value">Free</Field>
<Field name="value">Free</Field>
<Field name="value">Busy</Field>
<Field name="value">Busy</Field>
<Field name="value">Tentative</Field>
<Field name="value">Tentative</Field>

<xsl:for-each select="Field[@name='value'][position()&gt;number($start) and position()&lt;= number($end)]">
blah blah...
</xsl:for-each>

The believe the parser used is Saxon 8.7.3.

Thanks for any help,
gary

Postnext
Tony LavinioSubject: use javascript to get client time zone offset
Author: Tony Lavinio
Date: 14 Feb 2007 04:55 PM
Saxon supports calls to Java, not JavaScript.

You can do just about the same thing though with Java.

There are examples on the Saxonica web site of how to call Java
routines from Saxon.

Postnext
gary comstockSubject: use javascript to get client time zone offset
Author: gary comstock
Date: 14 Feb 2007 05:06 PM
My example above uses java and works quite well except I believe the java date object is not the invoked client side as javascript, its done server side as java.

When I change the time zone on my development machine to EST and have a simple html form using this javascript function:

function GetClientUTC()
{
var now = new Date();
var offset = (now.getTimezoneOffset() / 60)*-1;
return offset;
}

The value is as expected -5.

When I run the above XSLT example no matter what time zone I change my development machine always shows -6 which is CST and the time zone I reside along with all of our corporate servers so somehow the date object is being picked up somewhere other than my development machine.

thanks,
g

Posttop
Tony LavinioSubject: use javascript to get client time zone offset
Author: Tony Lavinio
Date: 15 Feb 2007 09:34 AM
Since you're into browser and Javascript territory, and neither is
part of Stylus Studio, and this is a Stylus Studio support forum,
you'll probably have to look elsewhere to go further.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.