Page 1 of 1

Registering Custom Extension for Saxon HE

Posted: Fri May 27, 2011 2:43 pm
by Briotti
Hi all. I'm working on a custom extension in order to provide some functions to XSLT by Saxon.

My firs approach was to test Saxon EE provided by Oxigen itself: I created a simple java class, put it in a jar and place this jar in <oxigenx install dir>/lib. Then declaring a namespace such xmlns:see="it.mypackage.MyExtensionClass" it is possible to use the method in a very simple way, calling the method as a normal function:

<xsl:value-of select="see:getString('testo di prova')"/>

By reflection implemented in Saxon EE, it works like a charm, and Oxygen can validate the function and parameters type too :-) (thanks Saxon, thanks Oxygen).

Second approach was porting such extension on Saxon HE. I created my extension accordingly with info provided on Saxonica and SourceForge web sites. I was able to compile the extension in a jar. Unfortunately indicate the extension in XSLT Scenario is not enough: the transformer is unable to access extension.

What I'm missing? I must create some kind of wrapper or custom XSLT Transformer?

Re: Registering Custom Extension for Saxon HE

Posted: Mon May 30, 2011 2:43 pm
by sorin_ristache
Hello,

Yes, you have to write a small Java class that starts the Saxon HE transformer. This is necessary because in Saxon HE your extension functions must be registered in a net.sf.saxon.Configuration object which you set to the Saxon HE transformer factory class (net.sf.saxon.TransformerFactoryImpl) with a call transformerFactory.setAttribute(net.sf.saxon.lib.FeatureKeys.CONFIGURATION, yourConfiguration). This call must be done before the factory creates the transformer, that is before the TransformerFactory.newTransformer() call. You can call your small Java class as an external XSLT processor in Oxygen.


Regards,
Sorin

Re: Registering Custom Extension for Saxon HE

Posted: Tue May 31, 2011 7:42 pm
by Briotti
thanks Sorin for your replay, that confirmed my suspects :-)

Well, supposing I would like to run such java class as a different xslt engine (say, CustomSaxon) inside the Oxygen IDE: is it possible to do? Can I configure a scenario that works with my CustomSaxon? And what parameter I must manage inside the class (i.e. of course, xml file, xsl file and output file, probably there are more?)

Thanks.

Re: Registering Custom Extension for Saxon HE

Posted: Wed Jun 01, 2011 9:20 am
by sorin_ristache
Yes, you can configure an external XSLT transformer based on your small Java class from menu Options -> Preferences -> XML -> XSLT-FO-XQuery -> Custom Engines. You have to select the created transformer in the Transformer combo box of your XSLT transformation scenario. Please look at the example of command line for an external engine in the User Manual. You specify the XML URL and XSL URL from the scenario in the command line of the external transformer using the ${xml} and ${xsl} editor variables. You can find the list of all available editor variables in the dialog box for configuring a custom engine by pressing the small green arrow button next to the Command Line text area.


Regards,
Sorin

Re: Registering Custom Extension for Saxon HE

Posted: Wed Jun 01, 2011 7:19 pm
by Briotti
Done! It works fine :-)

Thanks Sorin, and sorry for last trivial question... sometimes I forgot the manual :-(