DesignLiquido / xslt-processor

A JavaScript XSLT processor without native library dependencies
GNU Lesser General Public License v3.0
102 stars 31 forks source link

TypeError: e.match is not a function #26

Closed rmkanda closed 1 year ago

rmkanda commented 5 years ago

TypeError: e.match is not a function

Code:

const fs = require('fs');
const path = require('path');
const { xsltProcess, xmlParse } = require('xslt-processor');

const readFile = filePath => {
  return fs.readFileSync(path.resolve(__dirname, filePath));
};

const xmlString = readFile('./Sample.xml');
const xsltString = readFile('./Outbound.xsl');

const outputString = xsltProcess(xmlParse(xmlString), xmlParse(xsltString));

console.log(outputString);

Error:

/Users/test/node_modules/xslt-processor/dist/xslt-processor.js:1
(function (exports, require, module, __filename, __dirname) { "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var commonjsGlobal="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function createCommonjsModule(e,r){return e(r={exports:{}},r.exports),r.exports}var he=createCommonjsModule(function(e,r){!function(t){var a=r,n=e&&e.exports==a&&e,o="object"==typeof commonjsGlobal&&commonjsGlobal;o.global!==o&&o.window!==o||(t=o);var s=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,i=/[\x01-\x7F]/g,l=/[\x01-\t\x0B\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g,u=/<\u20D2|=\u20E5|>\u20D2|\u205F\u200A|\u219D\u0338|\u2202\u0338|\u2220\u20D2|\u2229\uFE00|\u222A\uFE00|\u223C\u20D2|\u223D\u0331|\u223E\u0333|\u2242\u0338|\u224B\u0338|\u224D\u20D2|\u224E\u0338|\u224F\u0338|\u2250\u0338|\u2261\u20E5|\u2264\u20D2|\u2265\u20D2|\u2266\u0338|\u2267\u0338|\u2268\uFE00|\u2269\uFE00|\u

TypeError: e.match is not a function
    at xmlParse (/Users/rmkanda/test/node_modules/xslt-processor/dist/xslt-processor.js:1:71118)
    at Object.<anonymous> (/Users/rmkanda/test/index.js:12:34)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
herveheritier commented 5 years ago

Hi, Solved for me by adding encoding parameter into the readFileSync call like this

const readFile = filePath => {
    return fs.readFileSync(path.resolve(__dirname,filePath),"utf-8")
}
jkorff commented 5 years ago

I had the same error and solved it by explicitly converting the input parameters to string:

const transformXml = require('xslt-processor');
transform = transformXml.xsltProcess(
    transformXml.xmlParse(String(xml)),
    transformXml.xmlParse(String(xsl))
);
leonelsanchesdasilva commented 1 year ago

I'll considered this as solved for now. Feel free to reopen if any modification is required.