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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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.

   
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.