3

I have a public static 0 argument function in Java that I am trying to call through XSLT in a webapp. When I run it in tomcat (5.5.34), it works fine, but when I run it in JBoss (6.1 final) I get the error

TransformerException: Instance method call to method getScoreXMLTagClass requires an
Object instance as first argument

I'm wondering if JBoss is using a different XSLT parser - I believe I want to use Xalan, and I've heard that Saxon (which is used in some parts of this webapp) can have compatibility issues with this kind of thing. Is there a way to tell which it's using/force it to use a different one? Apologies if I've missed some vital information here, this is not my area of expertise - let me know if some other info is needed.

edit: To show how this is being used, here's the code

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
...
xmlns:resources="java:com.example.MyResources"
<xmlns:rclass="java:com.example.MyClass">
    <xsl:template name="scoreString">
    <xsl:param name="string" />
    <xsl:value-of select="resources:getString(rclass:getData(),$string,null)"/>
</xsl:template>

<xsl:template match="/">
<xsl:if test="normalize-space(.)">
<div>
<xsl:for-each select="s:scores/s:score">
<xsl:for-each select="s:net">
<dl>
<dt>
    <xsl:call-template name="scoreString">
    <xsl:with-param name="string">network</xsl:with-param>
        </xsl:call-template>
    <xsl:value-of select="@id"/>
</dt>
...

I've shortened the class names to simplify it. The equivalent error would be

TransformerException: Instance method call to method getData requires an
Object instance as first argument

edit 2

the method is

public static final Class getData()
{
    return MyClass.class;
}
user1111284
  • 886
  • 1
  • 6
  • 23
  • Could you add a significant fragment of your XLST code (including namespace declaration, access to the java method, etc)? – Tomas Narros Mar 14 '12 at 13:54

2 Answers2

3

It seems that you need to use 'xalan://' instead of 'java:' to declare a java namespace, so

<xmlns:rclass="xalan://com.example.MyClass">

in this case. I'm not sure why it worked on tomcat and not JBoss, but it's possible they were picking up different versions of the Xalan jar.

user1111284
  • 886
  • 1
  • 6
  • 23
1

You're right that when calling out to Java, there are differences between Xalan and Saxon; at first sight it looks to me as if your stylesheet is designed to work with Saxon but is actually being run under Xalan. You can find out which product is actually in use by calling system-property('xsl:vendor') from any XPath expression.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • I messed that up a bit but it threw an 'org.xml.sax.SAXParseException', which I would assume is from saxon? Or is it not that easy? – user1111284 Mar 14 '12 at 15:25
  • No! I just read some more of the stack trace and under that there's another exception: 'org.apache.xalan.transformer...' so that must be my answer! Do you know what in my code above is specific to Saxon and might upset Xalan? – user1111284 Mar 14 '12 at 15:29
  • No, I don't. I'm not up to date with Xalan, and in any case, you haven't shown the Java code that it's trying to call. – Michael Kay Mar 14 '12 at 20:05