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
Igor KarpSubject: exception while calling java function with long argument
Author: Igor Karp
Date: 23 May 2007 01:42 PM
Hello All,

I am trying to use Java extension function to convert timestamps to local timezone. I am having trouble passing parameter of the type long to java.util.TimeZone getOffset method, but what is strange that the same value can be passed as a long to java.util.Date constructor.

The minimal example is below:

xml:
<?xml version="1.0"?>
<root>
<start_utc>2007-05-24T11:11:11Z</start_utc>
</root>

xslt:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0" exclude-result-prefixes="xs">
<xsl:output method="xml" indent="yes"/>

<xsl:variable name="tz">
<xsl:value-of xmlns:tz="java:java.util.TimeZone" select="tz:get-time-zone('Europe/Berlin')"/>
</xsl:variable>

<xsl:template match="start_utc">
<xsl:variable name="start_unix" as="xs:long">
<xsl:value-of select="((. cast as xs:dateTime - '1970-01-01T00:00:00Z' cast as xs:dateTime) div 'PT0.001S' cast as xs:dayTimeDuration) cast as xs:long"/>
</xsl:variable>
<testt>
<xsl:value-of xmlns:tz="java:java.util.TimeZone" select="tz:get-offset($tz, $start_unix)"/>
</testt>
<testd>
<xsl:value-of xmlns:d="java:java.util.Date" select="d:new($start_unix)"/>
</testd>
</xsl:template>

</xsl:transform>

the error i get is:
SXJE0021: Error in call to extension function {public int java.util.TimeZone.getOffset(long)}: Cannot convert supplied XPath value to the required type for the extension function

I have a workaround but I would really like to get some ideas how to fix this.

Regards,
Igor

Postnext
Minollo I.Subject: exception while calling java function with long argument
Author: Minollo I.
Date: 23 May 2007 03:22 PM
This seems a Saxon specific question, better asked on the Saxon discussion list. The problem is with the first argument, not the second one; a quick way to make it work is:
<xsl:value-of xmlns:tz="java:java.util.TimeZone" select="tz:get-offset(tz:get-time-zone('Europe/Berlin'), $start_unix)"/>

There are ways to declare variables as Java types in Saxon (wrapped java objects), but I haven't tried doing that.

Posttop
James DurningSubject: exception while calling java function with long argument
Author: James Durning
Date: 24 May 2007 01:18 PM
You appear to be calling the function with incorrect arguments. See:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/TimeZone.html

The 2 possible ways to call this are
getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds) OR
getOffset(long date)
but you are passing in 2 arguments.

I think you want:
<xsl:value-of xmlns:tz="java:java.util.TimeZone" select="tz:get-offset($start_unix)"/>
without the $tz passed in as an argument.

 
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.