Transforming XML with XSLT at the Command Line with saxon-js and xslt3

In this article, we’ll demonstrate how to transform XML documents using XSLT (Extensible Stylesheet Language Transformations) at the command line using node.js, saxon-js and xslt3.

First, make sure you have a recent version of Node.js installed. We recommend using nvm or nvm-windows (see A Step-by-Step Guide to Installing nvm-windows for Node.js Management).

Install saxon-js and xslt3

At the command line, run the following commands to install saxon-js and xslt3 globally:

npm install -g saxon-js

npm install -g xslt3

Transforming a File

  1. Navigate to the directory where your XML and XSLT files are located.
  2. Type the following command to transform your XML file using an XSLT stylesheet:
    xslt3 -xsl:your-stylesheet.xsl -s:your-xml-file.xml -o:output.xml
    Replace your-stylesheet.xsl and your-xml-file.xml with the names of your actual XSLT stylesheet and XML file. The transformed XML will be saved in output.xml.

If you want to return the result at the command line, leave out the -o parameter:

Running xslt3 at the command line

See for more information on using saxon-js and xslt3.

Warning about PowerShell

If you are using PowerShell, sometimes the way it parses command-line arguments can differ from the traditional Command Prompt. If you get an error like Command line option -s requires a value, try running the same command in Command Prompt.

Written by Nat Dunn. Follow Nat on Twitter.

Related Articles

  1. Transforming XML with XSLT at the Command Line with saxon-js and xslt3 (this article)
  2. How to Try XMLSpy for Free