AuthorDocumentController.evaluateXPath with custom extension

Post here questions and problems related to oXygen frameworks/document types.
Posts: 228
Location: Hamburg/Germany

AuthorDocumentController.evaluateXPath with custom extension

Fri Apr 11, 2014 9:19 am


in my custom frameworks I'm using xpath expressions defined as fixed attributes within the xsd that need to be evaluated when working with the document. When the document is beeing processed for pdf output or transformations with saxon xslt I can use my own extension functions within these xpath expressions.

However, during editing the document I'm using AuthorDocumentController.evaluateXPath to evaluate the xpath expression (for instance within the StyleFilter or LinkTextResolver).

Now I'm wondering if there's a way to register my own extension functions so they can be used in the path evaluated this way? Especially since you already have extension functions oxy:current-selected-element() and oxy:allows-child-element().

Thanks and regards,

Posts: 653

Re: AuthorDocumentController.evaluateXPath with custom exten

Fri Apr 11, 2014 3:05 pm

Hello Patrik,

Currently we don't have such an API. I can think of the following solutions:

1. Instead of using *AuthorDocumentController.evaluateXPath* create a transformer (you can specify the extensions functions to use) and execute it over the current document. Something like this:

Code: Select all

ExtensionFunctionDefinition[] saxonExtensions = ...;
Transformer transformer = access.getXMLUtilAccess().createSaxon9HEXSLTTransformerWithExtensions(styleSource, saxonExtensions);
InputSource inputSource = new InputSource(access.getEditorAccess().getEditorLocation().toString());
Source xmlSource = new SAXSource(inputSource);
transformer.transform(xmlSource, outputTarget);

2. The second solution involves using reflection to invoke your extension functions (reflexive extension functions):
2.1 Copy the jar with the extension inside Oxygen lib folder.
2.2 On an AuthorExtensionStateListener.activated declare the namespace mappings by executing a the code like the one below. Please note that the attribute is marked as being "notSpecified" (the false argument to the AttrValue) so it will not appear in the document.

Code: Select all

* @see ro.sync.ecss.extensions.api.AuthorExtensionStateListener#activated(ro.sync.ecss.extensions.api.AuthorAccess)
public void activated(AuthorAccess authorAccess) {
AuthorNode authorElement = authorAccess.getDocumentController().getAuthorDocumentNode().getRootElement();
authorAccess.getDocumentController().setAttribute("xmlns:date", new AttrValue("test.MyClass", "test.MyClass", false), (AuthorElement) authorElement);

2.3. On the LinkTextResolver or StylesFilter you can execute the XPath explicitly requesting XPath 3.0 (this will force Saxon PE as the transformer, which supports reflexive extensions functions):

Code: Select all

Object[] evaluateXPath = authorAccess.getDocumentController().evaluateXPath(

Best regards,

Return to “SDK-API, Frameworks - Document Types”

Who is online

Users browsing this forum: No registered users and 0 guests