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
- Navigate to the directory where your XML and XSLT files are located.
- 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
Replaceyour-stylesheet.xsl
andyour-xml-file.xml
with the names of your actual XSLT stylesheet and XML file. The transformed XML will be saved inoutput.xml
.
If you want to return the result at the command line, leave out the -o
parameter:
See https://www.npmjs.com/package/saxon-js 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.
Related Articles
- Transforming XML with XSLT at the Command Line with saxon-js and xslt3 (this article)
- How to Try XMLSpy for Free