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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With