Page 1 of 1

Xquery Transformation with API and external variables

Posted: Mon Aug 05, 2013 5:34 pm
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

Re: Xquery Transformation with API and external variables

Posted: Tue Aug 06, 2013 9:20 am
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