Overview for Developers

Libraries

Enketo maintains 4 libraries that can be used to build an Enketo-powered application. The illustration below shows how these 4 libraries are used as building blocks of one such application: Enketo Express.

Enketo Express

  • communication with OpenRosa server
  • persistent storage in browser
  • applicationCache in browser
client

Enketo Core

  • form rendering
  • form logic
  • form API

Enketo XPathJS

  • XPath evaluation
server

Enketo Transformer

  • XSL transformation of XForm
  • markdown processsing
  • language directionality
  • media/data resource URI resolution

Enketo XSLT

  • XSL stylesheets

These libraries are divided in a logical way so they can be used for light-weight mobile hybrid applications, as well as web applications. There is a lot of flexibility in using these libraries. For example you could use Enketo XSLT in your own transformer in the language of your choice.

Transformation

Enketo's form engine, Enketo Core, does not read XForms directly. It works with the result of a transformation of an XForm into a JSON object containing a form HTML string and a model XML string. The illustration below gives a high-level overview of this transformation.

XForm instances
<model>
  <instance>
    <data>
      <node/>
      <resp/>
    </data>
  </instance>
  <instance id="countries"/>
  ...
</model>
XForm binds
<bind 
  nodeset="/data/node" 
  relevant="/data/resp = 'a'"
  constraint=". > 6"
  type="integer"
/>
XForm body
<input 
  ref="/data/node"
  appearance="distress"
>
  <label>Enter Number</label>
</input>
XML instances
<model>
  <instance>
    <data>
      <node/>
      <resp/>
    </data>
  </instance>
  <instance id="countries"/>
  ...
</model>
HTML form
<form class="or">
  <label 
    class="...-distress"
  >
    <span>Enter Number</span>
    <input
      type="number"
      name="/data/node"
      data-relevant="/data/resp= 'a'"
      data-constraint=". > 6"
      data-type-xml="integer"
    />
  </label>
</form>

The transformation uses XSL and could theoretically be performed by any XSL Transformer in any language. It's been confirmed to work in PHP and NodeJS.