NodeJS library that transforms OpenRosa/ODK XForms into a format the Enketo understands. It works both as a library module, as well as a standalone app.
- nodeJS 8 and npm
npm install enketo-transformer --saveconst transformer = require('enketo-transformer');
const xform = fs.readFileSync( 'path/to/xform.xml' );
transformer.transform( {
// required string of XForm
xform: xform,
// optional string, to add theme if no theme is defined in the XForm
theme: 'sometheme',
// optional map, to replace jr://..../myfile.png URLs
media: {
'myfile.png' : '/path/to/somefile.png',
'myfile.mp3' : '/another/path/to/2.mp3'
},
// optional ability to disable markdown rendering (default is true)
markdown: false,
// optional preprocess function that transforms the XForm (as libXMLJs object) to
// e.g. correct incompatible XForm syntax before Enketo's transformation takes place
preprocess: doc => doc,
} ).then(function( result ){
// do something with result
});- clone repo
- install dependencies with
npm install
- start with
npm start - limited use with
GET /transformwith xform parameter (required, xform URL), or - full-featured use with:
POST /transformwith URL-encoded body includingxform(required, full XForm as a string),theme(optional, string), andmedia(optional, map) parameters
sample GET request:
curl http://localhost:8085/transform?xform=https://example.com/forms/78372/form.xml
sample POST request:
curl -d "xform=<xform>x</xform>&theme=plain&media[myfile.png]=/path/to/somefile.png&media[this]=that" http://localhost:8085/transform{
"form" : "<form>.....</form>",
"model": "<model>...</model>",
"transformerVersion": "1.13.0",
"languageMap": { "Français": "fr", "English": "en" }
}
- run tests with
npm test
The script npm run develop runs the app on port 8085 and also serves test/forms on port 8081. You could test the transformation output by placing an XForm in test/forms and running
http://localhost:8085/transform?xform=http://localhost:8081/autocomplete.xml
A vagrant configuration file and provisioning script is also included. Use DEBUG environment variable to see debug terminal output, e.g.:
DEBUG=api,transformer,markdown,language node app.jsSee license document. Also note the additional 'powered by enketo' footer requirement of enketo-xslt which is used in this repository and therefore applicable.
See change log