AskingSomething143
AskingSomething143

Reputation: 11

Call Java Function in XSLT2

I have the Java method ...

public static Object parseXMLtoXLSX(File xmlFile, String path)

So I want to call the method from XSLT.

I understand, that I have to introduce the class in my XSLT File e.g. like this:

<xsl:stylesheet version="2.0" xmlns:trans="pathToMyJavaClass">

But how can I call the method?

Is this the right way?:

<xsl:value-of select="trans:parseXMLtoXLSX($xmlFIle,$path)" />

But how can I store the Java File Object, that I get back from the Method in a Variable?

Edit: I can't show the < > in this question...

Upvotes: 0

Views: 345

Answers (1)

Michael Kay
Michael Kay

Reputation: 163322

The calling conventions from XSLT to other languages depend entirely on which XSLT processor you are using, so you need to provide this information.

If you're using XSLT 2.0 under Java then it's likely that the processor you are using is Saxon, in which case the calling conventions are documented at http://saxonica.com/documentation/index.html#!extensibility/functions

In cases where you're handling objects (like a Java java.util.File) that have no equivalent in the XDM data model used by XSLT, the calling conventions can be quite complicated. It's simpler if you organize things so that you only need to pass simple values like strings and integers. For example, write another method in Java that accepts a String (containing a file name) rather than a File.

Upvotes: 1

Related Questions