https://github.com/inist-cnrs/computron
Another Node.js library for applying XSLT stylesheets to XML documents
https://github.com/inist-cnrs/computron
addon nodejs xlst xml
Last synced: about 2 months ago
JSON representation
Another Node.js library for applying XSLT stylesheets to XML documents
- Host: GitHub
- URL: https://github.com/inist-cnrs/computron
- Owner: Inist-CNRS
- Created: 2018-09-25T09:13:14.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-08T03:25:16.000Z (over 3 years ago)
- Last Synced: 2025-08-31T08:38:01.459Z (10 months ago)
- Topics: addon, nodejs, xlst, xml
- Language: C++
- Homepage:
- Size: 3.41 MB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: License.en.txt
Awesome Lists containing this project
README
[](https://github.com/Inist-CNRS/computron/actions/workflows/build-and-test.yml)
[](https://badge.fury.io/js/computron)
# Computron
Computron is a Node.js library to apply XSLT stylesheets to XML documents. It's a [C++ addon for Node.js](https://nodejs.org/api/addons.html) that uses [libxml2](http://www.xmlsoft.org/) and [libxslt](http://xmlsoft.org/libxslt/).
## Disclaimer
**This library is only intended to be used on Linux.**
## Requirements
You must have libxml2 and libxslt1 installed on your system.
```
sudo apt install libxml2-dev libxslt1-dev
```
You should already have a C++ compiler installed on your system, if it's not the case install g++.
```
sudo apt install g++
```
Computron uses [node-gyp](https://github.com/nodejs/node-gyp) as a build system so you need to install it to be able to compile Computron
```
npm install -g node-gyp
```
## Usage
Basic example:
```JS
const Computron = require('computron');
const computron = new Computron();
// A stylesheet needs to be loaded on the current instance before doing anything
try {
computron.loadStylesheet('/path/to/stylesheet');
} catch (err) {
console.error(err);
process.exit(1);
}
// Apply the previously loaded stylesheet on the provided XML file
let xmlResult;
try {
xmlResult = computron.apply('/path/to/xml');
} catch (err) {
console.error(err);
process.exit(1);
}
console.info(xmlResult);
```
Using a stylesheet that takes parameters:
```JS
const Computron = require('computron');
const computron = new Computron();
// A stylesheet needs to be loaded on the current instance before doing anything
try {
computron.loadStylesheet('/path/to/stylesheet/with/params');
} catch (err) {
console.error(err);
process.exit(1);
}
// Apply the previously loaded stylesheet on the provided XML file
let xmlResult;
try {
// Parameters can be passed to the stylesheet
const params = {
param1Name: 'value1',
param2Name: 'value2',
};
xmlResult = computron.apply('/path/to/xml', params);
} catch (err) {
console.error(err);
process.exit(1);
}
console.info(xmlResult);
```
## Development
To build and run the tests in release mode run:
```
npm test
```
You can debug the C++ code with in VSCode, to do so run:
```
npm run build:config
```
This will build the VSCode debugger configuration, you can then simply press `F5` or go to the "Run and Debug" tab and click on "Debug".