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

Mark Baker mbaker at analecta.com
Tue Mar 5 12:16:37 CST 2013


George,

Thanks so much. This is the kind of service that really sets you guys apart
from the rest.

I'll let you know what success I have with what you have sent.

Thanks again,

Mark

> -----Original Message-----
> From: George Cristian Bina [mailto:george at oxygenxml.com]
> Sent: March 1, 2013 6:00 AM
> 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,
> 
> We will investigate further additions to the API to better support this
> usecase. In the meanwhile, I created a simple test framework using your
> elements to see what we can do using also the XSLTOperation on some
> actions. The advantage with this approach is that the delay you noticed
> does not appear anymore, because we replace the operational-failure
> element when we add or remove the description and thus its layout is
> refreshed.
> Please extract the attached archive in the oXygen frameworks folder - it
> should result in a folder called "mark" inside [oXygen]/frameworks.
> 
> Then open the [oXygen]/frameworks/mark/test.xml in oXygen and switch to
> the Author mode. From the Styles drop down from the toolbar switch
> between v1, v2, v3, and v4 to get different actions in the document and
> test to see how each of these work. These correspond to the mark1.css,
> mark2.css, mark3.css and mark4.css, respectively.
> 
> I defined a few actions, even a "noop" action that uses a 1 pixel
> transparent PNG icon that is invisible (we will solve this in the next
> version at the API level, adding a visible property on the button that
> can be set though an XPath expression).
> 
> Let me know your feedback on these editing modes.
> 
> Best Regards,
> George
> --
> George Cristian Bina
> <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
> http://www.oxygenxml.com
> 
> On 2/27/13 5:31 AM, Mark Baker wrote:
> > Thanks George,
> >
> > That's an interesting idea, but when I tried it, I found that the
invisible
> > gif I used was not invisible in the editor. It might work if I used one
that
> > matched my background color. However, the 2 second delay that you
> mention,
> > and which I observed, make it not really usable.
> >
> > In any case, it is still quite a convoluted way to achieve something I
think
> > should be simple if you want to create an input form interface rather
than a
> > traditional document interface, which, as you know, is something I
> advocate
> > strongly.
> >
> > I don't know what the answer is -- a custom CSS selector, a schema-aware
> > fragment insert operation that greys the button if the insert would be
> > invalid, a deactivate-button action -- but I think something is needed
to
> > complete the promise of the brilliant forms capability you have created.
> >
> > Thanks,
> >
> > Mark
> >
> > -----Original Message-----
> > From: George Cristian Bina [mailto:george at oxygenxml.com]
> > Sent: February-26-13 6:16 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,
> >
> > There is an oxy_xpath() extension function (not a selector) that can be
> used
> > to get an interesting behavior. I still use my section/title example
below
> > so you should adapt this to your actual elements:
> >
> > section:before {
> >       content:
> >           oxy_button(
> >               actionID, oxy_xpath('if (./title) then "delete.title" else
> > "add.title"'), transparent, true); }
> >
> > So, basically I can use the oxy_xpath() function to dynamically create
the
> > action name based on an XPath condition, in this case I check if a title
> > child element exists or not, but you can have any complex XPath
> > 2.0 expression there and cascade multiple if statements if needed.
> >
> > The only issue right now is that it takes about 2 seconds for the action
to
> > change into the other after it is invoked - we probably need to look
into
> > speeding that up - but the functionality is there and it should cover
your
> > use case.
> >
> > To get the action disappear I think that instead of the delete action
you
> > can define an action that does not do anything and that has a small
> > invisible icon and return that action instead of the delete one, but I
have
> > not tested this.
> >
> > Best Regards,
> > George
> > --
> > George Cristian Bina
> > <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
> > http://www.oxygenxml.com
> >
> > On 2/26/13 9:44 PM, Mark Baker wrote:
> >> 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