Skip to content

Instantly share code, notes, and snippets.

Last active Feb 19, 2020
What would you like to do?
XSLT/XML - CLI tricks with xsltproc and xmllint

Tricks from the Command Line: xsltproc and xmllint

Often, when writing an XSLT file, you’ll want to test it quickly, without contacting a FileMaker Server or otherwise accessing the rest of the world. On Linux and OS X, you can use the command-line utility, ‘xsltproc’, to run XSLT programs quickly:

xsltproc transform.xsl input.xml

This applies the stylesheet in the file transform.xml to the XML in input.xml, and writes the output to your terminal. You can instead write the output to a file:

xsltproc transform.xsl input.xml > output.xml

Another useful command-line tool is ‘xmllint,’ which can be used to prettify an XML file. For example, of your XML file, data.xml, has the contents:

<?xml version="1.0" encoding="utf-8"?>
<people >""><person><first>Thomas</first><last>Andrews</last><title>Developer</title></person><person><first>Mickey</first><last>Burns</last><title>Project Manager</title></person></people>

you can run the command:

xmllint -format data.xml

and get the output:

<?xml version="1.0" encoding="utf-8"?>
<people >"">
    <title>Project Manager</title>


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment