Reputation: 343
I have my custom Java function which performs something and I need to put it to XSL so it could perform something on selected nodes. I was using like this:
<msxsl:script implements-prefix="user" language="java">
<![CDATA[
public String doSomething(String input) {
// does something
return result;
}
]]></msxsl:script>
declaring namespaces:
... xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:user="example.com">
and call:
<xsl:variable name="var">
<xsl:value-of select="user:doSomething(node)"/>
</xsl:variable>
this resulted in "Could not compile stylesheet" error.
Also tried to replace java code with Javascript, error was same.
Do you know how to do this right or other methods how I can insert Java code into XSL and call it?
Upvotes: 1
Views: 1582
Reputation: 163262
The mechanisms for calling out from XSLT to other languages such as Java or Javascript depend on the XSLT processor you are using, and in general they are not portable across processors. The msxsl:script mechanism is specifically for Microsoft's MSXML.
The only two Java processors in common use nowadays are Xalan and Saxon, and both have mechanisms for calling out to Java code. The mechanisms are similar but differ in many details. But as Martin Honnen points out, extension functions are less likely to be needed with XSLT 2.0 (or 3.0) than with 1.0.
Upvotes: 1