Java fuctions in saxon:evaluate?
Added by Anonymous about 15 years ago
Legacy ID: #7615914 Legacy Poster: Olaf Märker (maerker)
Hello, I try to call a Java function with the saxon:evaluate method, but it did not work. The documentation says, that the expression 'may contain calls on Java extension functions'. So I do not know, if it is a bug or a misuse of me. The following XSLT works fine: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:Math="java.lang.Math" xmlns:saxon="http://saxon.sf.net/" version="2.0"> <xsl:output method="xml" encoding="UTF-8"/> <xsl:template match="/"> <Result> <xsl:value-of select="Math:abs(-1)"/> </Result> </xsl:template> </xsl:stylesheet> But not this one: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:Math="java.lang.Math" xmlns:saxon="http://saxon.sf.net/" version="2.0"> <xsl:output method="xml" encoding="UTF-8"/> <xsl:template match="/"> <Result> <xsl:value-of select="saxon:evaluate('Math:abs(-1)')"/> </Result> </xsl:template> </xsl:stylesheet> I got the error: Cannot find a matching 1-argument function named {java.lang.Math}abs() I use Saxon 9.1.0.5 Regards, Olaf Märker
Replies (3)
Please register to reply
RE: Java fuctions in saxon:evaluate? - Added by Anonymous about 15 years ago
Legacy ID: #7616618 Legacy Poster: Michael Kay (mhkay)
I'll investigate this next week when I'm back from vacation.
RE: Java fuctions in saxon:evaluate? - Added by Anonymous about 15 years ago
Legacy ID: #7631074 Legacy Poster: Michael Kay (mhkay)
There are two problems here. Firstly, you must use the namespace URI "java:java.lang.Math" rather than "java.lang.Math". Saxon supports the latter form (and a wide variety of alternatives) in XSLT, but only the first form in XPath or XQuery, and saxon:evaluate() follows the XPath rules. Secondly, when you fix this, Saxon throws a NullPointerException. This is specific to the fact that Math.abs() is an overloaded method which is only resolved to a specific method at runtime, based on the types of the supplied arguments. I will log this as a Saxon bug and publish a patch.
RE: Java fuctions in saxon:evaluate? - Added by Anonymous about 15 years ago
Legacy ID: #7633168 Legacy Poster: Olaf Märker (maerker)
Thank you very much, the Math:abs() was only an example to demonstrate the problem. For my own Java class it helped to add java: to the namespace :-)
Please register to reply