Subject: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.
<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.
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.
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.