RE: [xsl] calling java methods from a stylesheet

Subject: RE: [xsl] calling java methods from a stylesheet
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 21 Sep 2009 21:48:46 +0100
Firstly note that this changes in Saxon 9.2. With 9.2, picking up Java
methods from the classpath ("reflexive extension functions") is not
supported in Saxon-HE: you need Saxon-PE or Saxon-EE.

Other than that: use the -TJ flag on the command line for extra diagnostics.
This will explain where the software is looking for the extension function
which may help to explain why it wasn't found.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

> -----Original Message-----
> From: Garvin Riensche [mailto:g.riensche@xxxxxxx] 
> Sent: 21 September 2009 18:55
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] calling java methods from a stylesheet
> 
> Hi there,
>  
> i have some stylesheets which were written to be processed by 
> the xalan processor. Now I want to switch to saxon. These 
> stylesheets contain java methods that should be executed. 
> Therefore they include the following namespace 
> "xmlns:java="http://xml.apache.org/xslt/java";. The .jar file 
> which holds the java classes is included in the classpath. A 
> method call looks like the following:
> 
> <xsl:value-of 
> select="java:de.novum.vger.util.DateUtil.getTodayString()" />
> 
> which works fine with xalan.
> 
> How can I make these stylesheets work with saxon without 
> changing too much?
> 
> I thought it would work like this:
> 
> add namespace: xmlns:java="java:de.novum.vger.util.DateUtil"
> call method:
> <xsl:value-of select="java:getTodayString()" />
> 
> but I get the following error:
> Error at xsl:value-of on line 40 column 84 of 
> stylesheet_leistungsfall_variabel_dta.xsl
>   XPST0017: XPath syntax error at char 21 on line 40 in
> {java:getTodayString()}:
>     Cannot find a matching 0-argument function named
>   {java:de.novum.vger.util.DateUtil}getTodayString()
> 
> Why does saxon not find the class, although the jar-file 
> containing it is in the classpath?
> 
> regards,
> Garvin

Current Thread