Reputation: 2558
I am using Orbeon Form Builder to generate a form. I would like to delete an element (last one) from the model when the form is saved.
I have tried to create a delete action base on the examples in this link but cannot get it to work
Given the instance
<xf:instance id="fr-form-instance">
<guide>
<title/>
<media>
<format>image</format>
</media>
<media>
<format>video</format>
</media>
</guide>
</xf:instance>
I have the following delete action within my to delete the last media element
<xf:delete ev:event="xforms-submit" nodeset="guide/media" at="last()"/>
But it does not work.
I have also tried changing the xpath
<xf:delete ev:event="xforms-submit" nodeset="media" at="last()"/>
and wrapping in an action
<xf:action ev:event="xforms-submit">
<xf:delete nodeset="guide/media" at="last()"/>
</xf:action>
but still no joy!
The XForm is valid and you can save the data, it's just that the second media element still appears in the final XML data.
Upvotes: 0
Views: 389
Reputation: 25034
At a guess, your initial problem is that your XPath expressions are not selecting the element you want to delete. The expression "guide/media" isn't going to select anything (unless there is something important you're not showing us), since "guide" is the outermost element of the instance, and that's the default context node in XPath.
The rules for identifying the target of a deletion are complicated enough that I've never learned them and have to look at examples every time I need to delete anything. But the simplest way to perform a deletion (for me, at least) is to identify the nodes to be deleted in the nodeset attribute and leave the 'at' attribute out of it. So if it were me, I'd try
<xf:delete ev:event="..."
nodeset="media[last()]"/>
You should also check to make sure your listener is actually hearing the event. Putting a message into the same action is one good way to test for this, while debugging -- if you don't get the message, it's clear you have an event binding issue and not (or not just) an XPath issue.
Upvotes: 1