SaxonJS in NodeJS

Sep 14 2020

Ho problemi a importare SaxonJS nell'applicazione NodeJS.

const saxonJs = require("saxon-js");

console.log(Object.getOwnPropertyNames(saxonJs));
// [ ]

console.log(Object.getOwnPropertyNames(window.SaxonJS));

/**
[
      'atom',              'Atomic',
      'transform',         'Serializer',
      'serialize',         'StringWriter',
      'getProcessorInfo',  'getResource',
      'setLogLevel',       'getLogLevel',
      'setPlatform',       'getPlatform',
      'getNavigator',      'timeStamp',
      'internalTransform', 'checkOptions',
      'makeAtomicValue',   'getItemDetails',
      'XdmArray',          'XdmFunction',
      'XdmMap',            'U',
      'XError',            'XPath',
      'XS',                'Developer'
    ]
    */

const testOutput = saxonJs.transform({
                    stylesheetFileName: xslt_filepath,
                    sourceFileName: source_filename,
                    destination: 'raw',
                });
// returns TypeError: saxonJs.transform is not a function

window.SaxonJS.transform({
                    stylesheetFileName: xslt_filepath,
                    sourceFileName: inputFiles[j],
                    destination: 'raw',
                });
// XError: Cannot supply stylesheetFileName in browser

restituisce TypeError: saxonJs.transform non è una funzione

cosa sta succedendo?

Risposte

MichaelKay Sep 14 2020 at 19:48

Provare

require('SaxonJS2N.js')

Penso che tu abbia scelto la versione browser di Saxon-JS piuttosto che la versione Node.js.