NodeJS app to evaluate ODK XPath expressions using Enketo's XPath evaluator.
Not sure which versions of Node are compatible yet. It's just an MVP at this stage. It was built and tested on Node v8 and should work on later versions as well.
- Clone the repo (or copy the files)
- Run
npm install --production
from the installation folder - Run
npm link
from the installation folder. This will make thexpath-evaluate
command available globally on your machine.
(If this app is deemed useful it will be published on npm, and installation will become easier).
- To remove the links, run
npm unlink
and remove the xpath-evaluator-app folder.
The application has a single required XPath expression parameter and 2 options that can be provided using flags:
--xml
: path to an XML file--context
: the context path in which the XPath expression should be evaluated
Run it via the command line as shown below under Examples.
Errors are returned to stderr
and the XPath evaluation result as string is return to stdout
.
xpath-evaluate --help
You can try these out from the app's folder. The XML documents used for the sample results of these expressions are at test/xml.
xpath-evaluate 1+1
👉2
xpath-evaluate "1 + 1"
👉2
(spaces in expression requires use of quotation marks)xpath-evaluate "pad2('1')"
👉01
xpath-evaluate "/data/a" --xml test/xml/one.xml
👉a
xpath-evaluate "pad2( /data/a )" --xml test/xml/one.xml
👉0a
xpath-evaluate "count-selected( /data/a )" --xml test/xml/one.xml
👉1
xpath-evaluate "../a" --xml test/xml/one.xml --context "/data/b"
👉a
xpath-evaluate "/data/odk:b" --xml test/xml/namespaces.xml
👉b
xpath-evaluate "//*[@id='2']" --xml test/xml/one.xml
👉b
xpath-evaluate "//*[@id='2']/@id" --xml test/xml/one.xml
👉2
xpath-evaluate "//*[@CapiTalized='true']" --xml test/xml/one.xml
: 👉b