Search code examples
orbeonxforms

Changing default evaluation context inside an action object


Is there any XForms object which I could use to override default evaluation context inside an action object? We have xforms:group in body part but do we have any in xforms:action? It would simplify code where I often use the same Nodeset as a base element I'm operating on

I would like to receive such code:

<xf:action ev:event="DOMActivate">
  <?xf:context? ref="instance('main')/d:Content/d:Attachment[index('repeat-id')]"> <!-- ?? -->
    <xf:setvalue ref="d:FileName" value="..." />
    <xf:setvalue ref="d:Description" value="..." />
    <xf:setvalue ref="d:MimeType" value="..." />
    <xf:setvalue ref="d:Size" value="..." />
    <xf:setvalue ref="d:Location" value="..." />
  </?xf:context?>
</xf:action>

so I wouldn't have to repeat the whole path all over again.


Solution

  • The attribute you are looking for is context. As of XForms 1.1, the context attribute is only available officially on the insert and delete actions, but some implementations already support it on all actions, and it is scheduled for inclusion in XForms 2.

    <xf:action ev:event="DOMActivate" context="instance('main')/d:Content/d:Attachment[index('repeat-id')]">
        <xf:setvalue ref="d:FileName" value="..." />
        <xf:setvalue ref="d:Description" value="..." />
        <xf:setvalue ref="d:MimeType" value="..." />
        <xf:setvalue ref="d:Size" value="..." />
        <xf:setvalue ref="d:Location" value="..." />
    </xf:action>
    

    Note that ref is, as far as I know, not officially allowed on action.

    There is a difference between ref and context as planned for the upcoming XForms 2:

    • context only changes the XPath evaluation context
    • ref usually has other effects, such as binding a control, or specifying the destination of a value (setvalue), etc.

    In XForms 1.1, context on insert unfortunately also can indicate the insertion point, but XForms 2 plans to improve on that and deprecate that use of context.