Michael,
  The problem turned out to be that the declaration in XSLT should have been:
<xsl:value-of select="models:getString()" xmlns:models="java:com.bt.psalm.utils.model.ModelUtils"/>
 
  I had interpreted the example in you book as being that the namespace pointed to the package and not the class.
 
Thanks for the diagnostic tip.
 
Martin



From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of Michael Kay
Sent: 21 May 2008 14:22
To: 'Mailing list for the SAXON XSLT and XQuery processor'
Subject: Re: [saxon] How does Saxon gain access to external functions

The -TJ option on the command line can give you useful diagnostics here. The equivalent in the Java API is
 
tFactory.setAttribute(FeatureKeys.TRACE_EXTERNAL_FUNCTIONS, Boolean.TRUE);
 
The first thing it will tell you is whether the problem is finding the class or finding the method. If the class can't be loaded, it will give you a clue as to why. If the class can be loaded but the method isn't found, then typically it has the wrong number of arguments, isn't static, or isn't public.
 
You shouldn't need to set a special classloader unless you are doing something rather unusual.
 
Michael Kay
http://www.saxonica.com/


From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of martin.me.roberts@bt.com
Sent: 21 May 2008 13:48
To: saxon-help@lists.sourceforge.net
Subject: Re: [saxon] How does Saxon gain access to external functions

Hi,
  After much investigation I have confirmed that the classLoader being used in the call is able to see my method, yet when I call it from within the xslt it can not find the method, can you please confirm the following syntax is what you would expect to work?
 
        <xsl:variable name="provider">
                <xsl:value-of select="models:ModelUtils.getString()" xmlns:models="java:com.bt.psalm.utils.model"/>
        </xsl:variable>
 
I am trying to call the class com.bt.psalm.utils.model.ModelUtils and the method getString.
 
I have explicit set the classLoader before instantiation the Transformer Factory and if I use the following code it finds the method:
 

Thread.currentThread().getContextClassLoader().loadClass("com.bt.psalm.utils.model.ModelUtils").getMethod("getString");

I have called the TransformerFactory using:     TransformerFactory tfactory = TransformerFactory.newInstance("net.sf.saxon.TransformerFactoryImpl",getClass().getClassLoader());

Yet I still get:

Error at xsl:value-of on line 58 of bundleentry://117/xsl/xsd2example.xsl:
  XPST0017: XPath syntax error at char 29 on line 58 in {models:ModelUtils.getString()}:
    Cannot find a matching 0-argument function named
  {java:com.bt.psalm.utils.model}ModelUtils.getString()

 

Can you please help?

 

Martin

 



From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of Michael Kay
Sent: 20 May 2008 11:43
To: 'Mailing list for the SAXON XSLT and XQuery processor'
Subject: Re: [saxon] How does Saxon gain access to external functions

You need to ensure that the class containing the Java method is on the classpath (that's all)
 
Michael Kay
http://www.saxonica.com/


From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of martin.me.roberts@bt.com
Sent: 20 May 2008 11:28
To: saxon-help@lists.sourceforge.net
Subject: [saxon] How does Saxon gain access to external functions

Hi,
  I am running Saxon within an OSGI environment and I need to get it to call static java methods that are defined within the rest of the OSGI environment.  How do I get Saxon to know about these methods?  Is Saxon simply using the classpath available to discover any methods mentioned in the xslt sheet or do I have to explicitly define the 'connection'?
 
Martin