node.jssaxon-js

SaxonJS on Node.js


I'm trying to run an empty simple code snippet to test SaxonJS 1.1.0 on NodeJs v8.11.1 on Windows 10.

require('./Saxon-JS-1.1.0/SaxonJS.js');

But I got this error :

PS C:\XXX\sandbox\xsl-transformation> node main.js
C:\XXX\xsl-transformation\Saxon-JS-1.1.0\SaxonJS.js:17136
        setPlatform(JSTestDriver.platform);
                    ^
ReferenceError: JSTestDriver is not defined
at initialize (C:\XXX\sandbox\xsl-transformation\Saxon-JS-1.1.0\SaxonJS.js:17136:25)

Looking at the source code, I can see :

function initialize() {
    "use strict";
    if (inBrowser) {
        setPlatform(BrowserPlatform.platform);
        saxonPrint("Saxon-JS " + getProcessorInfo().productVersion + " in browser", 0);
    } else {
        // Currently only Nashorn. (Later need to distinguish from Node case)
        // Nashorn JSTestDriver
        setPlatform(JSTestDriver.platform);
        saxonPrint("Saxon-JS " + getProcessorInfo().productVersion + " in 
   Nashorn");

        // node NodePlatform
    }

    if (typeof platform.initialize === "function") {
        platform.initialize();
    }
}

It seems Node Platform is not implemented.

However, in the documentation, it is written :

We're talking here primarily about running Saxon-JS in the browser. However, it's also capable of running in server-side JavaScript environments such as Node.js (not yet fully supported in this release).

I deeply search a code snippet of SaxonJS/NodeJS but I did not find one. Has anyone a snippet code of SaxonJS working on NodeJS ?


Solution

  • I'm afraid the documentation was somewhat jumping the gun. We do have users who have reported getting the code to run under Node.js, and we have done it ourselves "in the lab", but it requires source code tweaks to the issued product. As released, the code runs under two platforms, the browser platform and Nashorn (and under Nashorn, it assumes our test harness which is not released).

    We're working on a version for Node.js. Doing this properly as a product needs a lot of functionality that isn't in the browser version, for example in XML parsing and serialization, debugging support, command line interfaces and APIs, etc.