Computron
:warning: Work in progress :warning:
Computron is a Node.js library for applying XSLT stylesheets to XML documents. It's also a C++ addon for nodejs which means it uses pure C++ code whith the help of libxslt library.
Requirements
This version has been tested in Ubuntu 18.04 with NodeJS v10.
sudo apt install cmake g++ libxml2-dev libxslt1-dev
Install
npm install computron
Usage
const Computron = require('computron');
const transformer = new Computron();
transformer.loadStylesheet('path/to/my/file.xsl', error => {
if (error) return console.log('dammit');
transformer.apply('path/to/my/file.xml', (error, result) => {
if (error) return console.log('bloody hell');
});
});
Promises with the help of bluebird package
const Promise = require('bluebird');
const Computron = require('computron');
Promise.promisifyAll(Computron.prototype);
const transformer = new Computron();
transformer.loadStylesheetAsync('path/to/my/file.xsl')
.then(() => transformer.applyAsync('path/to/my/file.xml'))
.then(result => {
})
.catch(console.error)
});
API
Computron.loadStylesheet(string, callback)
Computron.loadStylesheet('path/to/my/file.xsl', error => {
});
Computron.apply(string, [obj], callback)
Computron.apply('path/to/my/file.xml', { name: 'John DOE' }, (error, result) => {
});
Computron.apply('path/to/my/file.xml', (error, result) => {
});