Project

Profile

Help

Help w/ java extensions

Added by Anonymous over 19 years ago

Legacy ID: #2860804 Legacy Poster: Kyle (kmh27)

I'm having a little trouble with java functionality in Saxon on some older stylesheets that were working under Xalan. In several cases I pass in java objects (e.g. a ResourceBundle) that are used in the output. So in this case I define only a java namespace. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="java" ... define a param for the incoming object, which is passed in when the transform is run. <xsl:param name="bundle"/> and then use the object <xsl:value-of select="java:getString($bundle, 'helloWorld')"/> It looked like most of these issues were related to the class not being in the classpath. Although I think these were cases where an object was being defined in a namespace in the stylesheet. My object is just being passed in. As I mentioned these were working as expected with Xalan. I'm running as a web app within Tomcat. Any ideas? Am I missing something? Here's the trace: Error on line 114 of file:///usr/local/Tomcat/jakarta-tomcat-5.0.27/webapps/ROOT/WEB-INF/config/navigation.xsl: Cannot find a matching 2-argument function named {java}getString() ** Transformation error Cannot find a matching 2-argument function named {java}getString() ; SystemID: file:///usr/local/Tomcat/jakarta-tomcat-5.0.27/webapps/ROOT/WEB-INF/config/navigation.xsl; Line#: 114; Column#: -1 net.sf.saxon.xpath.DynamicError: Cannot find a matching 2-argument function named {java}getString() at net.sf.saxon.expr.ErrorExpression.iterate(ErrorExpression.java:58) at net.sf.saxon.expr.Atomizer.iterate(Atomizer.java:70) at net.sf.saxon.expr.FirstItemExpression.evaluateItem(FirstItemExpression.java:67) at net.sf.saxon.expr.CastExpression.evaluateItem(CastExpression.java:92)


Replies (4)

Please register to reply

RE: Help w/ java extensions - Added by Anonymous over 19 years ago

Legacy ID: #2860806 Legacy Poster: Kyle (kmh27)

BTW I am actually trying to call getString like so: <xsl:value-of select="java:getString($general, concat('nav.', @id))"/> Just in case that is affecting the code that is looking for a matching method.

RE: Help w/ java extensions - Added by Anonymous over 19 years ago

Legacy ID: #2860949 Legacy Poster: Michael Kay (mhkay)

In general there's no standard API for calling Java methods from XSLT - the way you do it depends on the processor. There are some techniques that will work successfully across Xalan and Saxon, but there are many others that will not. In this particular case, I've no idea what you expect getString() to do - what class is it in? For details of how to call Java methods from Saxon, see the "extensibility" page in the documentation: http://www.saxonica.com/documentation/extensibility/functions.html Michael Kay

RE: Help w/ java extensions - Added by Anonymous over 19 years ago

Legacy ID: #2861206 Legacy Poster: Kyle (kmh27)

I've read through the documentation on extensibility in Saxon. I'm not seeing an example of my use case. I am attempting to pass in an object that was instatiantiated outside of the transform as a parameter. In Xalan this notation: <xsl:value-of select="java:getString($bundle, 'helloWorld')"/> calls the getString(String str) method on the $bundle object. The first argument always represents the object to call the method on. Is this functionality supported in Saxon? Thanks!

RE: Help w/ java extensions - Added by Anonymous over 19 years ago

Legacy ID: #2861273 Legacy Poster: Michael Kay (mhkay)

With the Saxon binding to Java methods, the name of the class whose method you are calling must be explicit in the URI of the function name. If the object $bundle is a java.lang.ResourceBundle, then the call is <xsl:value-of select="bundle:getString($bundle, 'hello')" xmlns:bundle="java:java.util.ResourceBundle"/> Michael Kay

    (1-4/4)

    Please register to reply