Have ideas to improve npm?Join in the discussion! »

computron

1.1.8 • Public • Published

npm version Build Status

Computron

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');
    // do something with the result
  });
});

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 => {
    // do something with the result
  })
  .catch(console.error)
});

API

Computron.loadStylesheet(string, callback)

Computron.loadStylesheet('path/to/my/file.xsl', error => {
  // ...
});

Computron.apply(string, [obj], callback)

// With params
Computron.apply('path/to/my/file.xml', { name: 'John DOE' }, (error, result) => {
  // ...
});

// Without params
Computron.apply('path/to/my/file.xml', (error, result) => {
  // ...
});

Keywords

none

Install

npm i computron

DownloadsWeekly Downloads

64

Version

1.1.8

License

MIT

Unpacked Size

22.2 kB

Total Files

13

Last publish

Collaborators

  • avatar