Page 1 of 1

XPath involving ${selection}

Posted: Thu Jan 26, 2017 12:41 pm
by afuchs
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

Re: XPath involving ${selection}

Posted: Thu Jan 26, 2017 12:51 pm
by Radu
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/ ... ement.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

Re: XPath involving ${selection}

Posted: Thu Jan 26, 2017 1:18 pm
by afuchs
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

Re: XPath involving ${selection}

Posted: Thu Jan 26, 2017 2:46 pm
by Radu
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

Re: XPath involving ${selection}

Posted: Thu Jan 26, 2017 4:47 pm
by afuchs
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!

Re: XPath involving ${selection}

Posted: Fri Jan 27, 2017 9:37 am
by Radu
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

Re: XPath involving ${selection}

Posted: Thu May 09, 2019 8:29 am
by wbrisett
Did anything ever come of this? I can see a use for this in a project I'm working with now.

Re: XPath involving ${selection}

Posted: Tue May 14, 2019 2:58 pm
by alex_jitianu
Hello,

There's a new function named oxy:selected-elements() that returns the current selected elements. Give it a try and let us know if it solves your use case.

Best regards,
Alex