Xquery Transformation with API and external variables

Oxygen general issues.
bastjan
Posts: 3
Joined: Thu Dec 13, 2012 3:42 pm

Xquery Transformation with API and external variables

Post by bastjan »

Hi!

I would like to transform a given XML-File using the oXygen-Api and a Xquery-file. The Xquery takes an external variable as parameter

Code: Select all

declare variable $d external;
but I don't how (or even if) I can set this in java using the oxygen api. My variable $d ist supposed to contain the xml-file (or rather its path) to be processed. (I guess this corresponds to saxons -s switch).

Best regards,
bastian
alex_jitianu
Posts: 1009
Joined: Wed Nov 16, 2005 11:11 am

Re: Xquery Transformation with API and external variables

Post by alex_jitianu »

Hello,

You can create a transformer using Oxygen API through class ro.sync.exml.workspace.api.util.XMLUtilAccess. Getting access to an instance of the class depends if you are using plugin API or framework API. If you are using an workspace access plugin then you can get an instance using ro.sync.exml.workspace.api.PluginWorkspace.getXMLUtilAccess(). If you're using framework API then use ro.sync.ecss.extensions.api.AuthorAccess.getXMLUtilAccess(). To perform the transformation you can use something like this:

Code: Select all


    XMLUtilAccess xmlUtilAccess = authorAccess.getXMLUtilAccess();
try {
Transformer transformer = xmlUtilAccess.createXQueryTransformer(xquerySource, extensionJars, XMLUtilAccess.TRANSFORMER_SAXON_PROFESSIONAL_EDITION);

transformer.setParameter("d", pathToXMLFile);

Source xmlSource = new StreamSource(outputFileSystemID);
Result outputTarget = new StreamResult(outputFileSystemID);
transformer.transform(xmlSource, outputTarget);
} catch (TransformerConfigurationException e) {
e.printStackTrace();
}


Best regards,
Alex
Post Reply