10

I need to transform an XML document using XSLT in nodejs. I can’t seem to find a library for nodejs that is currently maintained and encompasses the full standard of XSLT.

Does anyone have any suggestions on a package or something in native nodejs to perform transformation?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
user3597741
  • 429
  • 1
  • 7
  • 13

2 Answers2

12

2020 Update

Saxon-JS 2 now supports XSLT 3.0 in Node.js and in the browser!


Former answer

Your only (pure JavaScript, XSLT standards compliant) hope is Saxon-JS, but it may not be entirely ready to run on Node.js yet:

Michael Kay reads Q/A here and may perhaps provide an update beyond what's listed in the above links.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • @user3597741: How did you find Saxon to be overly complicated? – kjhughes Aug 15 '19 at 13:18
  • Well you multiple pieces. Saxon-ee and Saxon-js. And there are charges. – user3597741 Aug 16 '19 at 11:39
  • Saxon-js is also not compatible with NodeJS. They are working on it but sounds far off – user3597741 Aug 16 '19 at 11:47
  • Charges: Professional developers do not hesitate to pay for tools; their time is worth orders of magnitude more. Compatible: I did say *it may not be entirely ready to run on Node.js yet* and provided several supporting references, some indicating third-party success with adaptations and several indicating intent and progress. Sorry not to have an ideal solution to tell you about right now. – kjhughes Aug 16 '19 at 12:11
  • 2
    Answer from Saxonica is that we're working on it. Currently passing about 99% of tests. But there's still some functionality we want to put in before we release (e.g. conformant HTML serialization) and some performance issues we want to iron out. Thanks for your patience. – Michael Kay Aug 28 '19 at 17:44
  • 2
    Saxon-JS 2 for Node.js is released today (12 June 2020) - package `saxon-js` on npm. – Michael Kay Jun 12 '20 at 16:19
  • @MichaelKay: That's great news! Congratulations on the [major release](https://www.saxonica.com/saxon-js/release-notes.xml#2.0) and major accomplishment!! – kjhughes Jun 12 '20 at 17:58
  • @MichaelKay First of all thanks for this library! However, the documentation on using `SaxonJS` isn't clear enough to run it on NodeJS. Problem I've encounter was that importing the npm package using `const SaxonJS = require('saxon-js');` didn't work. Although minified js file in `node_module` is hard to read, I was able to find that you are adding SaxonJS on `window` object. I think you need to update your documentation for nodejs users to indicate how to import SaxonJS in javascript file. – Milo Kang Sep 14 '20 at 14:23
  • @MichaelKay, saxon-js has not crashed a single time over about 100 calls. It also runs fast on the server. saxon-c for python crashes about 50% of the time. and won't even install on the (shared) server because the required C compiler is missing on that server. Are these different code bases? Is there a "saxon-js"y thing for python I should try out instead of saxon-c? Thanks! – toddmo Nov 03 '22 at 22:41
  • @toddmo Please don't ask questions in the form of a comment on a three-year-old answer to a different question! Please raise a new question that's specific to your problem. Yes, SaxonC is a completely different code base to SaxonJS. – Michael Kay Nov 04 '22 at 08:48
1

encompasses the full standard of XSLT

could be treated as "compliant with browser implementation" in order to reuse XSLT as in browser as on server side. Native client side implementation could be significant denominator as speed and CPU load is level of magnitude is different in comparison with JS-based implementation.

https://www.npmjs.com/package/xslt-processor is promising cross-tier compatible implementation of XSLT 1.0.

Sasha Firsov
  • 699
  • 8
  • 9