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:

"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>

That’s much easier to read.

Have questions? You can contact my team directly for more insights. Or, check out our other FileMaker posts to learn more about customizing your solution.

About The Author

1 thought on “Tricks from the Command Line: xsltproc and xmllint”

Leave a Comment

Your email address will not be published. Required fields are marked *