An extension step for XML Calabash to run JavaScript and NodeJS in XProc
This step runs JavaScript code either by reading it from the input port or from a reference to an external file.
<tr:javascript>
<p:with-option name="href" select="'test.js'"/>
</tr:javascript>
<tr:javascript>
<p:inline>
<c:data>
print('hello world')
</c:data>
</p:inline>
</tr:javascript>
The step implements the JavaScript engines Rhino from Mozilla and Nashorn from Oracle and the trireme library from Apigee for running node.js scripts inside the JVM.
- Java 1.8
- add the path to
JavaScriptExtension.java
and the jar files in thelib directory
to your Java classpath - edit your XProc config and add the class file
<xproc-config xmlns="http://xmlcalabash.com/ns/configuration"
xmlns:tr="http://transpect.io">
<implementation type="tr:javascript" class-name="JavaScriptExtension"/>
</xproc-config>
NodeJS code is just executed with Trireme and Rhino. Trireme doesn't support the newer JavaScript engine Nashorn. Please also note that there are differences between the JavaScript implementation of Rhino and NodeJS. There is a detailed list of supported features from Mozilla.