Page 1 of 1

XPATH evaluation of ancestor-or-self

Posted: Fri Nov 14, 2025 4:28 pm
by mknebel
We have written an external author action that is supposed to change a value in the @outputclass attribute of a DITA element. The action uses a context rule that should evaluate to the corresponding element, in this case, <image>.

The XPATH works fine if the caret is placed inside of the image element. However, it does not if the element is selected using the breadcrumbs or simply by clicking on it. This is counter-intuitive and seems wrong.

The problem is not the action but the evaluation of the XPATH itself, as can be demonstrated by the following picture:
oxy_problem_xpath.jpg
Is our understanding of the XPATH expression wrong or should it return the <image> element also when it is selected?

For reference, this is one operation within the action that we are designing:

Code: Select all

<a:operation id="ChangeAttributeOperation">
      <a:xpathCondition>ancestor-or-self::image[1][not(@outputclass)]</a:xpathCondition>
      <a:arguments>
        <a:argument name="elementLocation">ancestor-or-self::image[1]</a:argument>
        <a:argument name="name">outputclass</a:argument>
        <a:argument name="namespace"></a:argument>
        <a:argument name="value">${ask('Select image size', editable_combobox, ('small':'small';'medium':'medium';'large':'large'), 'small')}</a:argument>
      </a:arguments>
    </a:operation>
    
Is there a workaround to get this working in standalone and WebAuthor component?

Best regards
Marion

Re: XPATH evaluation of ancestor-or-self

Posted: Sat Nov 15, 2025 10:23 am
by Radu
Hi Marion,
The xpath is run having as context the element which contains the caret position.
If the image is selected, the caret is outside of the image.
Maybe you could use a combination of your xpath with this special xpath function we made:
https://www.oxygenxml.com/doc/versions/ ... ement.html
It should work for Oxygen desktop, for WebAuthor from what I remember we never disable our Author actions on the toolbar so we do not use the activation xpath for anything.
Regards,
Radu

Re: XPATH evaluation of ancestor-or-self

Posted: Thu Nov 20, 2025 12:02 pm
by mknebel
Hi Radu,
Thank you for your input. The special XPATH function solved the problem. We now have operations with ancestor-or-self and with oxy:current-selected-element() in the action. Works like a charm also in WebAuthor.

Best regards
Marion

Re: XPATH evaluation of ancestor-or-self

Posted: Thu Nov 20, 2025 8:40 pm
by Radu
Hi Marion,

Great, I'm glad!

Regards,
Radu