Michael,
  Thanks for your support and patience ( although you might be tearing your hair out quietly :) )
 
Martin


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

The construct
 
<xsl:variable name="connection">
  <xsl:value-of select="y"/>
</xsl:variable>
 
should almost always be replaced by
 
<xsl:variable name="connection" select="y"/>
 
Not just because it's one line instead of 3, not just because it's about 10 times faster, but also because it often gets rid of some subtle errors in your logic.
 
In this case the expression ModelUtils:getSesameRepositoryConnectionByString('local-catalog') returns a value of type RepositoryConnection (I assume); the xsl:value-of instruction converts this to a text node; and the "as" clause on the xsl:variable is then trying to convert the text node to a value of type RepositoryConnection, without success. Eliminating the xsl:value-of avoids the conversion to a text node and back again, which avoids the error.
 
In this code:
 
<xsl:variable name="subject" as="class:java.lang.String"><xsl:text>http://psalm.bt.com#BT-RandV-Catalog</xsl:text></xsl:variable>
 
remember that the "as" clause is there to declare the type of the variable, not to force any conversions. The type of this value is again a text node, so the value is inconsistent with the declared type. Make this an XPath string value:
 
<xsl:variable name="subject" select="'http://psalm.bt.com#BT-RandV-Catalog'" as="xs:string"/>
 
and the call to the extension function should work fine.
 
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 15:35
To: saxon-help@lists.sourceforge.net
Subject: Re: [saxon] How does Saxon gain access to external functions

Michael,
  Thanks for the information below - this has got me a stage further I am now getting:
 
Validation error at xsl:variable on line 9 of bundleentry://117/xsl/getData.xsl:
  FORG0001: Cannot convert to an external type
Validation error at xsl:variable on line 10 of bundleentry://117/xsl/getData.xsl:
  FORG0001: Cannot convert to an external type
 
In the style sheet:
 
<?xml version='1.0'?>
<
xsl:stylesheet version="2.0"
xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform"
xmlns:class=
"http://saxon.sf.net/java-type">
<
xsl:template match="/">
    <xsl:variable name="connection" as="class:org.openrdf.repository.RepositoryConnection">
        <xsl:value-of select="ModelUtils:getSesameRepositoryConnectionByString('local-catalog')" xmlns:ModelUtils="java:com.bt.psalm.utils.model.ModelUtils"/>
    </xsl:variable>
    <xsl:variable name="subject" as="class:java.lang.String"><xsl:text>http://psalm.bt.com#BT-RandV-Catalog</xsl:text></xsl:variable>
    <xsl:variable name="property" as="class:java.lang.String"><xsl:text>http://psalm.bt.com/psalmBase.owl#name</xsl:text></xsl:variable>
    <xsl:element name="test">
    <xsl:value-of select="APIUtils:getPropertyValueByString($connection,$subject,$property)" xmlns:APIUtils="java:com.bt.psalm.utils.api.APIUtils"/>
    </xsl:element>
<
/xsl:template>

<
/xsl:stylesheet>
 
Lines 9 and 10 are the variables subject and property.  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: 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