Because of the complexity of XML, transforming from one document structure to another can be arbitrarily complex. XSLT is the main language for declaring such transformations, and xsltproc can apply such transformations to XML documents. Let’s look at a simple use case, starting with an attribute–based configuration file v1.xml:

We’d like to keep the indentation but put each of the configuration values into a separate element for easier parsing. To do that we

  1. specify strip-space and output elements to control the indentation

  2. match “/”, the root of the document

  3. match the “db” and “host” child elements, transforming each of them separately

The result is v1-to-v2.xslt:


This page is a preview of The newline Guide to Bash Scripting

No discussions yet