Custom Action XPath

Oxygen general issues.
neon096
Posts: 45
Joined: Wed May 23, 2012 11:20 am

Custom Action XPath

Post by neon096 »

I've created an action using the InsertOrReplaceFragmentOperation. Whereby the user highlights a selection of text and marks up a link. However the schema contraints are that the <link/> tag cannot be nested.

Code: Select all


<para>
The quick brown fox jumped over the <link>lazy</link> dog.
</para>
So far I've not been able to work out the XPath to prevent the action from nesting the <link/> tag. I've used "self:para[not(descendant::link)]" but this doesn't work as a link may or may not be already present in the para.

So the question is how do I run the xpath on the selected text? Or do I need to write a custom action which extends the InsertOrReplaceFragmentOperation?
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Custom Action XPath

Post by Radu »

Hi Neil,

The context for the XPath expression used to activate a certain action is the element at the caret position.
Such cases like detecting if the selection contains certain elements cannot be expressed using just an XPath expression.

You should probably try to set a very permissive XPath for the action like true() and then call a custom AuthorOperation implementation.

The source code for "ro.sync.ecss.extensions.commons.operations.InsertOrReplaceFragmentOperation" is quite simple and should be available in our Author SDK:
http://www.oxygenxml.com/oxygen_sdk.htm ... horing_SDK

Using the API you have the possibility to see how the selection spans, get the parent node for the selection start and end offsets using:

Code: Select all

ro.sync.ecss.extensions.api.AuthorDocumentController.getNodeAtOffset(int)
then get access to the child nodes of that parent node by using this method:

Code: Select all

ro.sync.ecss.extensions.api.node.AuthorParentNode.getContentNodes()
and see if the child nodes are links and are in the ranges of that selection.

The ro.sync.ecss.extensions.api.AuthorDocumentController also allows you to run XPaths on the Author nodes structure.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply