Skip to content

Instantly share code, notes, and snippets.

@molotovbliss
Last active August 15, 2024 07:25
Show Gist options
  • Save molotovbliss/160c32d06cb5b07b7a4b00d24c1ef3ba to your computer and use it in GitHub Desktop.
Save molotovbliss/160c32d06cb5b07b7a4b00d24c1ef3ba to your computer and use it in GitHub Desktop.
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 >"http://www.filemaker.com/fmpxmlresult"><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 >"http://www.filemaker.com/fmpxmlresult">
  <person>
    <first>Thomas</first>
    <last>Andrews</last>
    <title>Developer</title>
  </person>
  <person>
    <first>Mickey</first>
    <last>Burns</last>
    <title>Project Manager</title>
  </person>
</people>

Source:

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