npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

trireme-xslt

v1.0.0

Published

An XSLT module optimized for the Trireme project

Downloads

10

Readme

trireme-xslt

This module presents an abstraction of XLST processing. It is specifically designed for the Trireme platform to allow efficient processing of XSLT when Node.js applications are run on Java.

Basically, when this module is running on Trireme, it uses the XSLT processor provided by the Java platform. When it is not, it uses the "node_xslt" module, which in turn uses libxslt.

Trireme is an implementation of Node.js on top of the Java virtual machine. It makes it possible to embed Node.js into applications where it would be more difficult to go currently, and gives direct access to native Java technologies from Node.js.

One technology that is particularly mature on Java is XML processing, and this module provides that access.

One advantage of this module is that it can use features of the Java language that allow the processing to take place in a thread pool, making it possible to take advantage of extra CPU cores for XSLT processing -- which can be CPU-intensive and is highly parallelizable. This happens automatically in Trireme when a callback is passed to the "transform" function.

In order to make it possible to test apps outside Trireme, this module will detect if it is running in Trireme and if not it will use the "node_xslt" module instead.

This module requires Trireme 0.7.4 or higher. For more on Trireme, check it out on GitHub:

https://github.com/apigee/trireme

Example

var fs = require('fs');
var xslt = require('trireme-xslt');

var stylesheetText = fs.readFileSync('../fixtures/samplestylesheet.xsl');
var cs = xslt.compileStylesheet(stylesheetText);

var input = '<Hello>This is some XML!</Hello>';

// Synchronous transformation
var result = xslt.transform(cs, input);

// Async transformation
xslt.transform(cs, input, function(err, result) {
  console.log('The result of the transformation is %s', result);
});

// Transformation with parameters
xslt.transform(cs, input, 
  { foo: 'foo', bar: 123 },
  function(err, result) {
    console.log('The result of the transformation is %s', result);
});

Functions

compileStylesheet(stylesheet)

Parses the specified XSLT stylesheet for future processing. "stylesheet" must be a string or a Buffer.

Compiling a stylesheet is an expensive operation. For best results, compile it once when the application is started, and re-use it for multiple transformations.

transform(compiledStylesheet, document, parameters, callback)

Transforms the XML based on the stylesheet. The stylesheet must previously have been compiled using "compileStylesheet."

If specified, "parameters" must be an object. Each property in the object will be passed as a parameter to the XSLT engine, so that it may be retrieved usign the "xsl:param" tag.

If "callback" is specified and a function, then the processing may proceed asynchronously. The result will be delivered via the callback. The first argument will be an Error if processing fails, and undefined otherwise. The second will be a string that represents the output of the transformation.

setTransformer(transformerClass)

Specifies which Java class to use for XSLT transformation.

Trireme Operation

When using this module on Trireme, XSLT processing is handled by the platform's "TransformerFactory." A different transformer may be specified by calling "setTransformer". If a callback is used, then "transform" runs the XSLT in a thread pool, so it can take advantage of multiple CPU cores.

Within Trireme, the number of concurrent XSLT processing jobs is limited to 8 in order to avoid blowing up the thread pool in extreme situations. This default may be adjusted by setting the Java system property "trireme.max.xslt.jobs".

Local Operation

When using this module outside Trireme, all features are implemented using the "node_xslt" module, which under the covers uses "libxslt." Outside Trireme, all transformations are performed synchronously.