XForms/Conditional Actions

Motivation
You want to conditionally perform an action based on an XPath Expression.

Method
We will use the if attribute of an action that is part of the XForms 1.1 specification. We will set up an event that will be triggered every time an instance becomes empty. We will create an action and set the observer attribute to watch for changes in the people instance.

Here is the code for the action itself:

This says to watch the people instance and if there is not a person in the people instance then insert one using the person-template instance.

Acknowledgments
This example was posted on the Mozilla XForms newsgroup by John L. Clark in December 10th of 2008.