xslt-processor
a JavaScript XSLT Processor
Last updated a year ago by johanneswilm .
LGPL-3.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install xslt-processor 
SYNC missed versions from official npm registry.

XSLT-processor

Build Status

A JavaScript XSLT processor without native library dependencies.

Howto

Install xslt-processor using npm::

npm install xslt-processor

Within your ES2015+ code, import the two main functions and apply them:

import { xsltProcess, xmlParse } from 'xslt-processor'

// xmlString: string of xml file contents
// xsltString: string of xslt file contents
// outXmlString: output xml string.
const outXmlString = xsltProcess(
	xmlParse(xmlString),
	xmlParse(xsltString)
);

To access the Xpath-parser, import it like this:

import { xpathParse } from 'xslt-processor'

If you write pre-2015 JS code, make adjustments as needed.

Introduction

XSLT-processor contains an implementation of XSLT in JavaScript. Because XSLT uses XPath, it also contains an implementation of XPath that can be used independently of XSLT. This implementation has the advantage that it makes XSLT uniformly available whenever the browser's native XSLTProcessor() is not available such as in node.js or in web workers.

XSLT-processor builds on Google's AJAXSLT which was written before XSLTProcessor() became available in browsers, but the code base has been updated to comply with ES2015+ and to make it work outside of browsers.

This implementation of XSLT operates at the DOM level on its input documents. It internally uses a DOM implementation to create the output document, but usually returns the output document as text stream. The DOM to construct the output document can be supplied by the application, or else an internal minimal DOM implementation is used. This DOM comes with a minimal XML parser that can be used to generate a suitable DOM representation of the input documents if they are present as text.

Tests and usage examples

New tests are written in Jest an can be run by calling: npm test.

The files xslt.html and xpath.html in the directory test are interactive tests. They can be run directly from the file system; no HTTP server is needed. Both interactive tests and automatic tests demonstrate the use of the library functions. There is not much more documentation so far.

Conformance

A few features that are required by the XSLT and XPath standards were left out (but patches to add them are welcome). See our TODO for a list of missing features that we are aware of (please add more items by means of PRs).

Issues are also marked in the source code using throw-statements.

The DOM implementation is minimal so as to support the XSLT processing, and not intended to be complete.

The implementation is all agnostic about namespaces. It just expects XSLT elements to have tags that carry the xsl: prefix, but we disregard all namespace declaration for them.

There are a few nonstandard XPath functions. Grep xpath.js for ext- to see their definitions.

References

Current Tags

  • 0.11.5                                ...           latest (a year ago)

10 Versions

  • 0.11.5                                ...           a year ago
  • 0.11.4                                ...           a year ago
  • 0.11.3                                ...           a year ago
  • 0.11.1                                ...           2 years ago
  • 0.11.0                                ...           2 years ago
  • 0.10.1                                ...           2 years ago
  • 0.10.0                                ...           2 years ago
  • 0.9.2                                ...           2 years ago
  • 0.9.1                                ...           2 years ago
  • 0.9.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 7
Dependencies (1)
  • he ^1.2.0
Dev Dependencies (11)

Copyright 2014 - 2016 © taobao.org |