How to run XSLT from the command line
Skills required | XML |
---|---|
Time required (minutes) | 15 |
Intended audience | Developer |
Difficulty | Easy |
Category | Document |
Objective
XSLT is a programming language from the World Wide Web Consortium (W3C). The primary design objective of XSLT is to transform the content and structure of XML documents to a non-XML syntax such as plain text or HTML, or from one XML structure to another. This tutorial shows how to process an XSLT transformation using the Windows command line.
Prerequisites
To complete this tutorial requires:
- Software to read and write zip files (e.g. 7-Zip or on Windows right-click Extract all/Send to Compressed).
- Access to the command prompt on a local computer (on Windows run
cmd
); - A decent text editing program such as Notepad++, Sublime or something other than Windows Notepad, which has problems with the line endings.
- The sample files for this tutorial are available on GitHub
Tutorial
Installing an XSLT processor
To interpret and run XSLT code requires an XSLT processor. The steps below will install the Saxon XSLT processor on Windows.
- If it is not already present, install Java as follows:
- Go to https://www.oracle.com/java and choose Java SE download.
- Download the JDK or JRE .exe for windows (x64 for 64 bit) and run it.
- Go to https://www.saxonica.com , download the latest SaxonHE
.zip
file and unzip the contents to:
c:\saxon
Run the XSLT code
- Create a data folder (e.g.
c:\ps\films
) on the computer and copy to it: - the input XML file (
wikipediafilms.xml
) - the XSLT code file (
films.xsl
) - Open a command prompt in the data folder (e.g. c:\ps\films) and use Saxon to process the XML with the XSLT code. For example:
> java -jar c:\saxon\saxon-he-12.5.jar -s:wikipediafilms.xml -xsl:films.xsl -o:myoutput.xml
Open the output .psml
files in the data folder using a text editor to check the content.