Page 1 of 1

XSLT with Java extension

Posted: Mon May 17, 2010 5:37 am
by BlackFrancis
Hello,
I'm using the XSLT capability to import Java functions (using xmlns:java declaration). This works when I perform the transformation as part of my Java application, but when the xslts are loaded in the Oxygen editor, the classes are not found.
Error is:
The URI com.mycompany.Utilities does not identify an external Java class
Is there a way to set a Java classpath in the Oxygen editor, so that this can work in the editor?
:?:

Re: XSLT with Java extension

Posted: Mon May 17, 2010 9:52 am
by sorin_ristache
Hello,

You have to set the jar file with your XSLT extensions as an extension of the XSLT transformation scenario (the Extensions button of the dialog).


Regards,
Sorin

Re: XSLT with Java extension

Posted: Tue May 18, 2010 9:20 pm
by BlackFrancis
Thank you, that works for executing the transformation within the stand-alone editor.

Is there a similar setting to use, so that when I have the extended XSLT open in the Eclipse plugin, it doesn't flag the extensions as missing functions? The extension classes are part of the current Java project - it would be nice if the plugin picked up the project's class path automatically.

Re: XSLT with Java extension

Posted: Tue May 18, 2010 9:38 pm
by BlackFrancis
my apologies - that does seem to be the way it works

Re: XSLT with Java extension

Posted: Tue May 18, 2010 9:39 pm
by BlackFrancis
or does it? I'm confused now (obviously)

Re: XSLT with Java extension

Posted: Wed May 19, 2010 9:16 am
by adrian
Hello,

You can do the same thing in the Oxygen Eclipse plugin but if you want to use the existing sources you should add the classes(bin) folder of the Java project to the Extensions instead of the jar.
Also, make sure that your project is built automatically.

Regards,
Adrian

Re: XSLT with Java extension

Posted: Tue Jan 10, 2012 3:00 am
by jeff_gaer
Sorin

The link in your response on adding a java extension is broken. What is the format for the URL on the Add extension dialog

Re: XSLT with Java extension

Posted: Tue Jan 10, 2012 10:04 am
by sorin_ristache
Hello,

You open the dialog box for adding the XSLT extensions by pressing the Extensions button from the XSLT tab of the scenario dialog box.


Regards,
Sorin

Re: XSLT with Java extension

Posted: Tue Jan 10, 2012 11:18 am
by adrian
Hi,

The dialog Add extension accepts a normal URL(as your web browser). Note that you don't have to enter the URL manually, you can simply browse for a local file(use the Browse button on the right).
e.g. a file URL

Code: Select all

file:/D:/frameworks/docbook/xsl/extensions/saxon65.jar
Additionally, you can use editor variables to point to various locations known to Oxygen
e.g.

Code: Select all

${pdu}/extensions/saxon65.jar
Where ${pdu} is the URL that points to the current project directory(where the Oxygen project file, .xpr, is saved).

Regards,
Adrian

Re: XSLT with Java extension

Posted: Tue Jan 10, 2012 7:55 pm
by jeff_gaer
Using Oxygen v 12

In the extensions dialog for the transform scenario

file://home/jgaer/test.jar

jar -xvf /home/jgaer/test.jar | grep Extensions.class
extracted: com/ticomgeo/web/Extensions.class
jgaer@ljgaer_~:

package com.ticomgeo.web;

public class Extensions {
public static String prependTicomGeo(String s){
return "TICOMGEO"+s;
}
}

Still getting the error

SystemID: /data/databackup2/migrated/jgaer/Untitled10.xsl
Engine name: Saxon-PE 9.3.0.5
Severity: fatal
Description: Cannot find a matching 1-argument function named {java:com.ticomgeo.web.Extensions}prependTicomGeo(). External function calls have been disabled
Start location: 17:60
URL: http://www.w3.org/TR/xpath20/#ERRXPST0017

Re: XSLT with Java extension

Posted: Wed Jan 11, 2012 6:26 pm
by adrian
Hello,

Make sure extension functions are enabled in the Advanced options of Saxon-PE.
Edit the transformation scenario(Document > Transformation > Configure Transformation Scenario, Edit), and in the XSLT tab press the Advanced options(small cogwheel icon) button on the right of the Transformer combo.

At the bottom of the dialog, under Saxon-PE specific options there is an option that has to be enabled: Allow calls on extension functions (-ext)

Regards,
Adrian

Re: XSLT with Java extension

Posted: Wed Jan 11, 2012 8:12 pm
by jeff_gaer
Hi, I enabled the external calls but then found out Saxon HE does not support external calls. We do not have a license for PE. I have switched to xsl 1.0 and xalan but having similar problems , also a bit confused on one point but this may be better asked on a xalan forum.

For xalan I did not see any advanced options ( or options at all for that matter).

Also it is not clear of the protocal component of the namespace URI should be xalan or java, I've found examples of both on the web.

Thanks in advance for any help.

Re: XSLT with Java extension

Posted: Wed Jan 11, 2012 8:18 pm
by jeff_gaer
Sorry should have included more detail.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:java_lang="http://xml.apache.org/xalan/java/java.lang"
xmlns:tgi="java://com.ticomgeo.web.Extensions"
exclude-result-prefixes="xs xd"
version="1.0">
<xd:doc scope="stylesheet">
<xd:desc>
<xd:p><xd:b>Created on:</xd:b> Jan 9, 2012</xd:p>
<xd:p><xd:b>Author:</xd:b> jgaer</xd:p>
<xd:p></xd:p>
</xd:desc>
</xd:doc>
<xsl:template match="*">
<root>
<xsl:value-of select="tgi:prependTicomGeo(foo)"></xsl:value-of>
</root>
</xsl:template>
</xsl:stylesheet>

with xalan

SystemID: /data/databackup2/migrated/jgaer/Untitled10.xsl
Engine name: Xalan
Severity: fatal
Description: java.lang.NoSuchMethodException: For extension function, could not find method org.apache.xml.utils.NodeVector.prependTicomGeo([ExpressionContext,] ). - For extension function, could not find method org.apache.xml.utils.NodeVector.prependTicomGeo([ExpressionContext,] ).

with xlstproc
Engine name: Xsltproc
Severity: warning
Description: xmlXPathCompOpEval: function prependTicomGeo not found

Engine name: Xsltproc
Severity: warning
Description: XPath error : Unregistered function

Engine name: Xsltproc
Severity: warning
Description: runtime error: file file:/data/databackup2/migrated/jgaer/Untitled10.xsl line 18 element value-of

Engine name: Xsltproc
Severity: warning
Description: xsltValueOf: text copy failed

Engine name: Xsltproc
Severity: warning
Description: error: file file:/data/databackup2/migrated/jgaer/sample.xml

Engine name: Xsltproc
Severity: warning
Description: xsltRunStylesheet : run failed

Engine name: Xsltproc
Severity: warning
Description: xmlXPathCompOpEval: function prependTicomGeo not found
.....
SystemID: /data/databackup2/migrated/jgaer/Untitled10.xsl
Engine name: Xsltproc
Severity: fatal
Description: The transformer process ended with code: 9

I garnered the syntax for the transform from http://xml.apache.org/xalan-j/extension ... l#java_ext

Re: XSLT with Java extension

Posted: Tue Jan 17, 2012 10:27 am
by sorin_ristache
Hi,
jeff_gaer wrote:Hi, I enabled the external calls but then found out Saxon HE does not support external calls. We do not have a license for PE.
Oxygen includes Saxon PE and Saxon EE too, not only Saxon HE. Did you try to set Saxon PE transformer in the dialog box for running the transformation?
jeff_gaer wrote: xmlns:tgi="java://com.ticomgeo.web.Extensions"

...

I garnered the syntax for the transform from http://xml.apache.org/xalan-j/extension ... l#java_ext
You did not declare the Xalan extension correctly. If you look at the Xalan page about Java extensions you see:

Code: Select all

xmlns:date="http://xml.apache.org/xalan/java/java.util.Date"
You have to use:

Code: Select all

xmlns:tgi="http://xml.apache.org/xalan/java/com.ticomgeo.web.Extensions"

Regards,
Sorin