XPath involving ${selection}

Post here questions and problems related to oXygen frameworks/document types.
afuchs
Posts: 15

XPath involving ${selection}

Thu Jan 26, 2017 12:41 pm

Dear Developers,

When defining an action in Author Mode, is it possible to involve the current selection made by the user e.g. in the XPath controlling the action? One of the problems that I am trying to solve is to avoid nesting of a certain element when surrounding a selection; I'd check for the presence of the element by "xpathing" into the selection, for example. In general, it could be of advantage if I could check for the presence of any XML tag inside what the user is trying to edit/format in some way.

I know I can first tag the selection with an arbitrary tag, then remove the tag through XSLT, all done a sequence of actions; but this might interfere, for example, with change tracking (if the action involves a dialog that can be clicked away, it is cancelled, but the rest of the sequence is executed anyway).

So the question is, can I code this kind of control into a single action?

Thank you in advance,
Alexey
Radu
Posts: 5137

Re: XPath involving ${selection}

Thu Jan 26, 2017 12:51 pm

Hi Alexey,

For the action activation xpath modes we have a special function extension called oxy:current-selected-element():

https://www.oxygenxml.com/doc/versions/18.1/ug-editor/topics/oxy-current-selected-element.html

which would give you the current selected element if the user selects an entire element.

But if the end user selects some random content including text, elements and so on, we do not have a oxy:current-selected-content() function which would retrieve some kind of a node set containing the current selected nodes. If you are interested in such a function I could try to add an internal issue to consider adding it.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
afuchs
Posts: 15

Re: XPath involving ${selection}

Thu Jan 26, 2017 1:18 pm

Hi Radu,

Thank you for the prompt reply!

I am currently working with 17.1 for a certain reason, so probably even oxy-selected-element() would not be available. But it's anyway about the second case that you mention, and yes, I think it could be a sensible addition for the field "If this XPath expression is true".

I wonder what happens if I try the xpath_eval() in an argument on ${selection}?

Regards,
Alexey
Radu
Posts: 5137

Re: XPath involving ${selection}

Thu Jan 26, 2017 2:46 pm

Hi Alexey,

So:

I am currently working with 17.1 for a certain reason, so probably even oxy-selected-element() would not be available.


It should also be available in 17.1
But it's anyway about the second case that you mention, and yes, I think it could be a sensible addition for the field "If this XPath expression is true".


I will add an internal issue for this.

I wonder what happens if I try the xpath_eval() in an argument on ${selection}?


I do not understand what you mean, maybe you could elaborate. As far as I know the ${selection} editor variable is only expanded in parameter values.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
afuchs
Posts: 15

Re: XPath involving ${selection}

Thu Jan 26, 2017 4:47 pm

Hi Radu,

As far as I know the ${selection} editor variable is only expanded in parameter values.


Exactly. So if I try to write an XPath expression that should select, say, one of two actions to be taken depending on the XML structure of the selection, it probably won't work?

Let's say I want to replace a selection if it contains a certain element, or retain it and add a fragment if it does not, all in response to the same button activation by the user. I would want to select the action not by checking where the cursor is through XPath, but by applying the XPath to the selection itself. I realize that this is vague, but I hope that the requirement is clear.

Thank you!
Radu
Posts: 5137

Re: XPath involving ${selection}

Fri Jan 27, 2017 9:37 am

Hi Alexey,

I understand, we'll try to find some time to see if we can implement the extension oxy:current-selected-content() xpath function in order to provide the selected nodes.

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

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

Who is online

Users browsing this forum: No registered users and 1 guest