6

I am trying to create a custom XSLT function, but every time I receive this error:

'The first argument to the non-static Java function 'compareCI' is not a valid object reference.'

  <xsl:stylesheet version="2.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:foo="http://whatever">

  <xsl:function name="foo:compareCI">
    <xsl:param name="string1"/>
    <xsl:param name="string2"/>
    <xsl:value-of select="compare(upper-case($string1),upper-case($string2))"/>
  </xsl:function>

  <xsl:template match="/">
      <xsl:value-of select="foo:compareCI('red','blue')"/>
  </xsl:template>

</xsl:stylesheet> 

I hope someone of you can help me .Thanks a lot in advance.

3
  • 1
    It is working fine at my end in Oxygen. It is giving result '1' when comparing 'red' with 'blue', and '0' when comparing 'red' withn'red' Commented Apr 23, 2013 at 8:42
  • 1
    How do you run your XSLT and with which processor? (I used Saxon-HE 9.4.0.6 and it works) Commented Apr 23, 2013 at 8:52
  • I don't know which version used Java. My Java code is TransformerFactory factory = TransformerFactory.newInstance(); Source xslt = new StreamSource(new File("/home/xxx/xxx/aliformater-1.xslt")); Transformer transformer = factory.newTransformer(xslt); Commented Apr 23, 2013 at 10:17

1 Answer 1

7

I think you are trying to run this using Xalan, which is an XSLT 1.0 processor and therefore doesn't recognize xsl:function. What's happening is that (a) Xalan ignores the xsl:function, because an XSLT 1.0 processor that is given a stylesheet specifying version="2.0" is supposed to ignore things it doesn't understand (called "forwards compatibility mode" in the spec); and then when it sees the function call to foo:compareCI() it thinks this must be a call to an external Java method.

You need to run this with an XSLT 2.0 processor, typically Saxon.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.