SaxonJS ใน NodeJS

Sep 14 2020

ฉันมีปัญหาในการนำเข้าแอปพลิเคชัน SaxonJS ไปยัง 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

ส่งคืน TypeError: saxonJs.transform ไม่ใช่ฟังก์ชัน

เกิดอะไรขึ้น?

คำตอบ

MichaelKay Sep 14 2020 at 19:48

ลอง

require('SaxonJS2N.js')

ฉันคิดว่าคุณเลือกใช้ Saxon-JS เวอร์ชันเบราว์เซอร์มากกว่าเวอร์ชัน Node.js