Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSLTProcessor is not defined in node.js

Tags:

node.js

xml

xslt

I am trying to transform XML to XHTML. I have used XSLTProcessor in client side (Angular) and it's working fine. Now I am trying to use the same code in Node JS but it's not working and I am getting error message as XSLTProcessor undefined. Below is the client side code. Please suggest me the methods available for transformation in Node JS side.

transformXml(xml, xsl) {
  var html;
  if (this.isIE) {
    html = xml.transformNode(xsl);
  } else {
    var xsltProcessor = new XSLTProcessor();
    xsltProcessor.importStylesheet(xsl);
    var xmlDom = xsltProcessor.transformToDocument(xml);

    var serializer = new XMLSerializer();
    html = serializer.serializeToString(xmlDom.documentElement);
  }

  return html;
}
like image 336
Prithivi Raj Avatar asked Jul 26 '26 00:07

Prithivi Raj


1 Answers

XMLTProcessor() is not part of Node.js. You need a package like https://www.npmjs.com/package/xslt or similar - there are a number of packages for XSLT: https://www.npmjs.com/search?q=xslt.

like image 99
chrwahl Avatar answered Jul 28 '26 14:07

chrwahl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!