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

Mark Baker mbaker at analecta.com
Tue Feb 26 13:44:47 CST 2013


Hi George,

Thanks for the wonderfully detailed response. This information definitely
needs to be in the documentation.

Here's what I am trying to do. I have an element <operational-failure> that
has a compulsory element <description>, and an optional element
<occurrence>. In my CSS, I have a button attached to
operational-failure:after that allows the author to add an <occurrence>
element. 

The occurrence element is allowed only once, so once the occurrence element
had been added, I would like to do one of the following, in order of
preference:

* Hide the button altogether.
* Disable the button (grey it out).
* Display an informative message when the button is pressed.

Because the <operational-failure> element is not empty, the empty selector
doesn't seem to help me achieve the first option.

Putting in an XPath test of "not(occurrence)" does not give me the second
option (greying out the button), but it does give me the third option, in a
generic way. But the message is not really appropriate for use with a
button. It says:

"The action +occurrence is not available in the current location"

That would make sense if the user was selecting an action from a menu, and
had placed their caret where they want the action to occur. With a button,
though, the user does not know that an "action" is being invoked, and they
have no control over the location where the action takes place -- that is
dictated by the button.  So the message does not really tell the user why
the button action can't be completed.

Actually, the message they get without the button action being disabled is
actually more informative, because then they get the "element not allowed at
this location" dialog.

Neither of these is really satisfactory, though, because it is a universal
interface convention that if an operation is unavailable, the button/menu
that performs it should either be hidden or unavailable (greyed-out).

I haven't got my head around the XSLT Operation yet, so I'm not sure if it
provides a solution. 

What I can suggest as ways to address this class of problem are:

* an oXygen CSS extension for selecting elements based on their child
elements

* if a button is attached to an unavailable action, grey out the button

* provide a way to specify a custom message when an action is not available
in a particular context

Thanks for your help,

Mark

-----Original Message-----
From: George Cristian Bina [mailto:george at oxygenxml.com] 
Sent: February-26-13 1:45 PM
To: Mark Baker
Cc: oxygen-user at oxygenxml.com
Subject: Re: [oXygen-user] What is "When this XPath expression is true"
action parameter relative to?

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