Re: [xsl] Saxon extension functions

Subject: Re: [xsl] Saxon extension functions
From: Michel Hendriksen <michel.hendriksen@xxxxxxxxx>
Date: Fri, 10 Dec 2010 15:33:12 +0100
Thnx. I guess some samples on the net could use an update.

Michel

On Fri, Dec 10, 2010 at 3:04 PM, Michael Kay <mike@xxxxxxxxxxxx> wrote:
> In XSLT 2.0, a call to an unknown function is a static error even if the
> call is never executed. You need to do the test in use-when, which operates
> at compile time:
>
> <xslt:template name="seed">
>  <xslt:value-of use-when="function-available('date:new') and
>           function-available('date:get-time')"
> xmlns:date="java:java.util.Date"
>      select="date:get-time(date:new())"/>
>
>  <xslt:value-of use-when="not(function-available('date:new') and
>           function-available('date:get-time'))"
> xmlns:date="java:java.util.Date"
>      select="seconds-from-duration(current-time() - xs:time('00:00:00'))"/>
>
> </xslt:template>
>
> Michael Kay
> Saxonica
>
>
> On 10/12/2010 12:38, Michel Hendriksen wrote:
>>
>> Hi all,
>>
>> New topic. I made an extension function which is working in SaxonB.
>> When porting this to SaxonHE, where it is not supported, I get an
>> error that a matching function cant be found. This is expected. But
>> I'm testing for support of this and that seems to pass. So how do I
>> test for existing support? See my code below.
>>
>> <xslt:template name="seed">
>>        <!-- Works with SaxonB only! -->
>>        <xslt:choose>
>>                <xslt:when test="function-available('date:new') and
>> function-available('date:get-time')" xmlns:date="java:java.util.Date">
>>                        <xslt:variable name="date" select="date:new()"/>
>>                        <xslt:value-of select="date:get-time($date)"/>
>>                </xslt:when>
>>                <xslt:otherwise>
>>                        <!-- NOT random at all.....to be replaced by
>> something else -->
>>                        <xslt:variable name="time" select="current-time()"
>> />
>>                        <xslt:value-of select="seconds-from-time($time) +
>> 60 *
>> minutes-from-time($time) + 3600 * hours-from-time($time)"/>
>>                </xslt:otherwise>
>>        </xslt:choose>
>> </xslt:template>
>>
>> Error
>>
>> Error at xslt:variable on line 64 column 52 of selector.xsl:
>>   XPST0017 XPath syntax error at char 0 on line 64 in {date:new()}:
>>     Cannot find a matching 0-argument function named
>> {java:java.util.Date}new(). Note that
>>   direct calls to Java methods are not available under Saxon-HE
>> Error at xslt:value-of on line 65 column 50 of selector.xsl:
>>   XPST0017 XPath syntax error at char 0 on line 65 in
>> {date:get-time($date)}:
>>     Cannot find a matching 1-argument function named
>> {java:java.util.Date}get-time(). Note
>>   that direct calls to Java methods are not available under Saxon-HE
>>
>> line 64/65 are
>>
>>                        <xslt:variable name="date" select="date:new()"/>
>>                        <xslt:value-of select="date:get-time($date)"/>
>>
>> So within test.
>>
>> Michel Hendriksen
>> Kensas bv

Current Thread