Getting started

JavaScript implementation of XSLTProcessor for browser environments and Node.js CLI. This package provides a complete implementation of the W3C XSLTProcessor API that can be used as a drop-in replacement for the native browser implementation.

Background

Chrome and other browsers are deprecating native XSLTProcessor support:

  • Chrome 143+: XSLTProcessor starts showing deprecation warnings
  • Chrome 164 (August 2027): Full removal of native XSLT support

This library ensures your XSLT-based applications continue to work regardless of browser support.

Features

  • 1:1 Native API Compatibility: Drop-in replacement for native XSLTProcessor
  • XSLT 1.0: Every element and function of the W3C XSLT 1.0 Recommendation, with the few gaps listed under Known Deviations
  • XPath 1.0 Engine: Built-in XPath evaluator with all core functions
  • xsl:output Serialization: transformToString() honors method, indent, doctype, CDATA sections and disable-output-escaping
  • Zero Dependencies: The library has no runtime dependencies; only the xslt command line tool needs jsdom (an optional peer dependency)
  • Multiple Formats: ESM, CommonJS, and browser IIFE bundles
  • TypeScript Support: Includes TypeScript declarations

Documentation

The documentation is also published as a website with an interactive playground: https://xslt-processor.tradik.com/ (playground).

GuideContents
API ReferenceXSLTProcessor methods, parameters, xsl:output serialization, module exports, XsltEngine options, TypeScript
Loadersxsl:import, xsl:include and the document() function
Complete ExampleA product list transformed into an HTML table (browser and CLI)
Command Line Toolxslt options, base directory, includes, input encodings
ConformanceW3C compliance tables, supported elements and functions, known deviations, test coverage
Security LimitsXPath and XSLT limits, prototype pollution protection, input validation
Browser CompatibilityMinimum browser versions, native XSLT removal timeline, feature detection
Benchmarks1.1.3 vs 1.2.0: speed-up, time and peak memory per scenario, with charts, tables and npm run bench to reproduce
DevelopmentSetup, tests, Docker, Makefile, publishing to npm
Style GuideProject colors with WCAG 2.2 contrast ratios

All guides are listed in the documentation index.

Installation

npm install @tradik/xslt-processor

The library itself has no dependencies. The xslt command line tool also needs jsdom (an optional peer dependency, >=25), see CLI Usage.

Quick Start

Use a CDN for the easiest browser integration - no build step required:

<!-- jsDelivr (recommended) -->
<script src="https://cdn.jsdelivr.net/npm/@tradik/xslt-processor@1/dist/xslt-processor.browser.min.js"></script>

<!-- or unpkg -->
<script src="https://unpkg.com/@tradik/xslt-processor@1/dist/xslt-processor.browser.min.js"></script>

<script>
  // XSLTProcessor is the native one, or this polyfill when native XSLT is unavailable
  const processor = new XSLTProcessor();

  // Load and transform XML
  const parser = new DOMParser();
  const xslt = parser.parseFromString(xsltString, 'application/xml');
  const xml = parser.parseFromString(xmlString, 'application/xml');

  processor.importStylesheet(xslt);
  const result = processor.transformToFragment(xml, document);
  document.getElementById('output').appendChild(result);
</script>

The bundle defines the global XsltProcessorLib (all module exports) and calls installGlobal(): window.XSLTProcessor is replaced only when the browser has no working native implementation. To always use this implementation, call XsltProcessorLib.installGlobal(true) or use new XsltProcessorLib.XSLTProcessor().

CDN URLs:

CDNURL
jsDelivrhttps://cdn.jsdelivr.net/npm/@tradik/xslt-processor@1/dist/xslt-processor.browser.min.js
unpkghttps://unpkg.com/@tradik/xslt-processor@1/dist/xslt-processor.browser.min.js

Tip: Use @1 for the latest 1.x version, or an exact version such as @1.1.3 for pinning.

Browser (Local Install)

If you prefer local installation:

<script src="node_modules/@tradik/xslt-processor/dist/xslt-processor.browser.min.js"></script>
<script>
  // XSLTProcessor is now available globally
  const processor = new XSLTProcessor();
  // ...
</script>

ESM Module

import { XSLTProcessor, installGlobal } from '@tradik/xslt-processor';

// Optional: Force install as global XSLTProcessor
installGlobal();

// Or use directly
const processor = new XSLTProcessor();
const parser = new DOMParser();

// Load and parse XSLT stylesheet
const xsltText = await fetch('template.xsl').then(r => r.text());
const xsltDoc = parser.parseFromString(xsltText, 'application/xml');
processor.importStylesheet(xsltDoc);

// Load and parse XML source
const xmlText = await fetch('data.xml').then(r => r.text());
const xmlDoc = parser.parseFromString(xmlText, 'application/xml');

// Transform
const fragment = processor.transformToFragment(xmlDoc, document);
document.getElementById('output').appendChild(fragment);

CommonJS

const { XSLTProcessor } = require('@tradik/xslt-processor');

const processor = new XSLTProcessor();
// ...

Node.js

Node.js has no DOM, so bring one such as jsdom. The filesystem loader example is a complete Node.js script, and the API Reference covers every method.

CLI Usage

The package includes a command-line tool for transforming XML documents.

Without Node.js, use the standalone executable attached to every GitHub release (Linux x64/arm64, macOS x64/arm64, Windows x64), installed with a checksum check:

curl -fsSL https://raw.githubusercontent.com/spagu/XSLT-Processor/main/scripts/install.sh | bash

See Standalone executables for manual installation. With Node.js, the command line tool needs a DOM implementation, so install jsdom next to the package. It is an optional peer dependency: library users do not need it. Without it, xslt exits with an explanation instead of a stack trace.

# Global installation
npm install -g @tradik/xslt-processor jsdom

# Transform XML with XSLT
xslt data.xml template.xsl

# Save output to file
xslt data.xml template.xsl -o result.html

# With parameters
xslt data.xml template.xsl -p title="My Page" -p count=10

# Format output with indentation
xslt data.xml template.xsl -f -o output.html

# Override the output method and drop the XML declaration
xslt data.xml template.xsl --method text
xslt data.xml template.xsl --no-declaration

See Command Line Tool for all options, the base directory, xsl:include/document() resolution and input encodings.

Known Deviations

The main differences from XSLT 1.0 / XPath 1.0 and from libxslt:

  • xsl:number ignores lang and letter-value;
  • unparsed-entity-uri() always returns '';
  • numbers convert to strings in the XPath 1.0 form (10000000000), where libxslt writes 1e+10.

Details and workarounds: Known Deviations.

Contributing and Security

License

BSD-3-Clause License - see LICENSE.md for details.

This page is generated from README.md in the repository. Corrections are welcome as a pull request to that file.