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 W3C standard programming language primarily designed to process XML content. One task it is particularly well suited to is transforming XML to another syntax such as plain text or HTML or to an alternate XML structure. This tutorial shows how to do 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 that is not Windows Notepad. Notepad will have problems with the line endings.
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 for Developers / Java SE.
- Download the JDK or JRE .exe for windows (x64 for 64 bit) and run it.
- Go to http://sourceforge.net/projects/saxon/files/ , download the latest SaxonHE
.zip
file and unzip it to thec:\saxon
folder.
Run the XSLT code
- Create a data folder (e.g.
c:\ps\films
) on the computer and copy to it: - the input XML files (
*.xml
) - the XSLT code file (
*.xsl
) - Open a command prompt in the data folder and use Saxon to process the XML with the XSLT code. For example:
> java -jar c:\saxon\saxon9he.jar -s:myinput.xml -xsl:myxslt.xsl -o:myoutput.xml
Open the output in a text editor to check the content.