Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call an external java function with Xalan processor

I'm having trouble to call an external java function in my XSL code with Xalan processor.

The error I get is :

Exception in thread "main" java.lang.RuntimeException: java.lang.NoSuchMethodException: For extension function, could not find method org.apache.xml.utils.NodeVector.incrementPropertyId([ExpressionContext,] ).

I have a java class named Util.java in the folder where I execute my compile command.

In my xsl file, I've declared my namespace as follow :

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                          xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java"
                          xmlns:util="xalan://Util">

And I call my function using :

<xsl:copy-of select="util:incrementPropertyId(blablabal)"/>

So I suppose my problem comes from my namespace, but what is wrong with it ?

Also, It's a xsl 1.0 stylesheet.

Thanks for your help

Edit :

In my Util.java file, I have no package declared since I'm at the root... should I add a package Util; definition to my class ?

like image 885
Jean-François Savard Avatar asked Sep 15 '26 02:09

Jean-François Savard


1 Answers

define your name space util in the extension-element-prefix, and assign to this namespace the package and the name of your class:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                      xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java"
                      extension-element-prefix="util"
                      xmlns:util="your.package.YourClass">
like image 179
Mauro P. Avatar answered Sep 16 '26 14:09

Mauro P.