XPath involving ${selection}

Post here questions and problems related to oXygen frameworks/document types.
afuchs
Posts: 19
Joined: Mon May 19, 2014 11:38 am

XPath involving ${selection}

Post 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
Radu
Posts: 9057
Joined: Fri Jul 09, 2004 5:18 pm

Re: XPath involving ${selection}

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
afuchs
Posts: 19
Joined: Mon May 19, 2014 11:38 am

Re: XPath involving ${selection}

Post 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
Radu
Posts: 9057
Joined: Fri Jul 09, 2004 5:18 pm

Re: XPath involving ${selection}

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
afuchs
Posts: 19
Joined: Mon May 19, 2014 11:38 am

Re: XPath involving ${selection}

Post 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!
Radu
Posts: 9057
Joined: Fri Jul 09, 2004 5:18 pm

Re: XPath involving ${selection}

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
wbrisett
Posts: 38
Joined: Thu Feb 21, 2013 11:44 pm

Re: XPath involving ${selection}

Post by wbrisett »

Did anything ever come of this? I can see a use for this in a project I'm working with now.
alex_jitianu
Posts: 1009
Joined: Wed Nov 16, 2005 11:11 am

Re: XPath involving ${selection}

Post 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
Post Reply