Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create custom XSLT function

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.

like image 514
javagc Avatar asked Apr 23 '13 08:04

javagc


1 Answers

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.

like image 186
Michael Kay Avatar answered Oct 22 '22 10:10

Michael Kay