[oXygen-user] What is "When this XPath expression is true" action parameter relative to?

George Cristian Bina george at oxygenxml.com
Tue Feb 26 12:45:11 CST 2013


Hi Mark,

As you move the caret in the document the element that contains the 
caret becomes the current element where that XPath expression is evaluated.

Let's assume we have a section element that should contain a title 
element and we define an add.title action that adds the title element in 
the section. We can do this using the

ro.sync.ecss.extensions.commons.operations.InsertFragmentOperation

with the following parameters:

Fragment: <title></title>
Insert location: ancestor-or-self::section
Insert position: Inside as first child

and we can make this action available when we are inside a section, by 
setting the "when this XPath expression is true" field to

ancestor-or-self::section

Now, if the section defines only one title then we can enhance the 
condition to

ancestor-or-self::section[not(title)]

and the action will become active only when the caret is in a section 
without a title.

When an action is contributed to the Author page though the oxy_button() 
CSS extension function then the context for the XPath expression is the 
element on which we added the button.

For example, we can add this action on the before pseudo-element of a 
section, like below:

section:before {
     content:
         oxy_button(
             actionID, "add.title", transparent, true);

This will add the title element on a section without a title and on a 
section with title it will give a message that the action is not 
available anymore in that context - we disable the action on the toolbar 
when it is not available but this was not implemented
when the actions are added inline in the author.

In version 14.2 we added support for :empty selectors so you may want to 
see if that is useful for your use case. For example if I modify the 
above CSS rule to match an empty section

section:empty {
     content:
         oxy_button(
             actionID, "add.title", transparent, true);
}

then the behavior is nice, as I get a button if the section is empty, I 
press the button and I get the title while the button disappears.

Another thing that you may want to investigate is the XSLTOperation. 
This allows you to use an XSLT stylesheet to specify what the operation 
will actually do. The XSLT script can be something like

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="2.0">
   <xsl:include href="scripts/action1.xsl"/>
</xsl:stylesheet>

and the include will be resolved relative to the framework file 
location, so then you will add in your framework folder

scripts/action1.xsl

and edit that stylesheet to actually implement the processing you want. 
The advantage of doing this is that you can interactively develop and 
test the action: you can change the action1.xsl, save it, invoke the 
action in the XML document the Author mode, undo if you are not happy 
with the result, change the XSLT file again, try again the action, and 
so on.

Maybe if you can provide some more details about what you want to do we 
can provide better advise.

Best Regards,
George
--
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

On 2/26/13 7:07 PM, Mark Baker wrote:
> What is the “When this XPath expression is true” parameter of an action
> definition evaluated relative to? The docs just say “an XPath expression
> that applies to elements and attributes;” but they don’t say what the
> current element is at the time the xpath is evaluated.
>
> My reason for asking is this: I want to create a button to add an
> element to a document. But since this element is only allowed once
> inside its parent element, I would like the button to either disappear
> or be disabled if the parent element already contains the element that
> the button inserts.
>
> Ideally, I would like to do this using the stylesheet to remove the
> button when the child element already exists, but CSS does not provide a
> selector for an element that contains (or does not contain) another
> element, so there does not seem to be a way to do that. (Enhancement
> request for an Oxygen CSS extension for this purpose)
>
> So since that does not work, my next approach is to invalidate the
> button if the child element already exists. To do this, I think I would
> need the “When this XPath expression is true” parameter to be evaluated
> relative to the path specified in the “insertLocation” parameter, but
> that does not seem to be how it works.
>
> So, what is the current element when “When this XPath expression is
> true” parameter is evaluated.
>
> And, more generally, can anyone think of a way to do what I am trying to
> do here?
>
> Thanks,
>
> Mark
>
>
>
> _______________________________________________
> oXygen-user mailing list
> oXygen-user at oxygenxml.com
> http://www.oxygenxml.com/mailman/listinfo/oxygen-user
>


More information about the oXygen-user mailing list