orbeon

Orbeon Forms: How to use xPath within an Action


Another silly question from a beginner:

How do you use xPath within an Action?

   <xf:action observer="GetURL-control" event="DOMActivate" type="xpath">
        var mySysResult = 'true' 
       xf:if ((mySysResult = 'true') then (/SystemResult = mySysResult) else 
              (/SystemResult =mySysResult = 'false'))
    </xf:action>

Solution

  • I'm usually writing simple logic into value attribute in xf:setvalue, like this:

    <xf:action observer="GetURL-control" event="DOMActivate">
        <xf:setvalue ref="//SystemResult" value="if (xxf:non-blank(//control-1)) then 'true' else 'false'"/>
    </xf:action>
    

    You can use if statement even as attribute of xf:action. This can be helpful if you have more elements under xf:action.

    <xf:action observer="GetURL-control" event="DOMActivate" if="//SystemResult = 'OK'">
       <xf:setvalue ref="//SystemResult" value="'OK'"/>
       <xf:setvalue ref="//SystemResult2" value="'OK'"/>
    </xf:action>