Introduction to XForms

The essence of XForms is state, which means that it meshes extremely well with the REST (Representational State Transfer) architectural style [3].

An XForms application has two parts: a model, and a user-interface.

The model contains all the data being used, stored in instances, along with descriptions of properties of, and relationships between, the data. For instance, data can be defined inline:

<instance>
   <tests xmlns="">
      <test pass="" res="" req="valid">2018-01-20</test>
      <test pass="" res="" req="invalid">2018/01/20</test>
   </tests>
</instance>

or can be imported from an external source:

<instance src="tests.xml"/>

Descriptions of data properties are done using bind statements that bind properties to data values:

<bind ref="today" type="date"/>
<bind ref="color" readonly="../variant="'basic'"/>
<bind ref="state" required="../country="'USA'"/>
<bind ref="state" relevant="../country="'USA'"/>
<bind ref="total" calculate="../number * ../unitprice"/>
<bind ref="height" constraint=". > 0"/>

Controls in the user-interface then bind to the data to allow interaction:

<input ref="age" label="Age:"/>

After initialisation the system is in stasis: the data matches the descriptions, and the relationships between data are up-to-date. After that, events occur, either system-generated or user-initiated, causing data values to change, to which the XForms system responds in order to return the system to stasis. While in general the system responds to events in standard ways, applications can also catch events and specify actions that define how to respond to particular events in particular ways:

<action ev:event="xforms-value-changed">
   <setvalue ref="unsaved">true</setvalue>
</action>

As a --simple-- example, a map application might keep the x and y coordinates of a location and a zoom level for looking at the map:

<instance>
   <map xmlns="">
      <zoom>10</zoom>
      <x>511</x>
      <y>340</y>
      <url/>
   </map>
</instance>

The URL of the relevant map tile for that location can then --automatically-- be kept up-to-date whenever and however any of the values change, by using a bind:

<bind ref="url"
      calculate="concat('http://tile.openstreetmap.org/',
                        ../zoom, '/', ../x, '/', ../y, '.png')"/>

See [4] for a further introduction to XForms, and [5] for a fully worked-out mapping application in XForms.