Templating Tools

Templating tools are about separating data from tool specific file formats. And about getting nice pictures fast.

Templating

Most DFT applications require many similar calculations in order to find out how specific properties depend on certain input parameters. This requires a "design of experiment" (DOE). Another common task is to collect data and transform them into a format that allows visualization or analysis of the data. These tasks can be realized through templating, i.e. the automated creation of files which differ only in small parts from a fixed template and a set of different values.

Adopting XML as data description language we can benefit from the very advanced XML tools. One of these is the templating language XSLT.

XSLT

The XML Stylesheet Language Transformations (XSLT) - language defines such templates. The basic idea is the one illustrated in the following picture:

xslt.002.png

Some specific input data is transformed to a specific output according to a template. In the case of XSLT the input data must be XML, the template is an XSLT template, and the output is XML or any other text format.

xsltproc

The tool we recommend to use for these transformations on the command line is xsltproc. It works in the following way:

xsltproc template.xsl data.xml>outputfile

Select data from input

In order to replace space-holders in the template with data from the input one requires some way of addressing these data. In the world of XML this is done by XPATH. XPATH allows to select node sets with a unix directory like path string. It provides syntax to express conditions, so-called predicates. XPATH also provides a set of functions and operations to evaluate expressions with nodes, numbers, and text.

A good resource for XPATH is:
http://www.w3schools.com/Xpath/xpath_intro.asp
Selecting nodes:
http://www.w3schools.com/Xpath/xpath_syntax.asp
The functions reference:
http://www.w3schools.com/Xpath/xpath_functions.asp

Writing a template

Use the templates on the Template Market and try them out. The basic work flow of developing XSLT templates is always:

  1. Get the data you are interested in in XML.
  2. Get an example of an output file you intend to generate and name it yourtemplatename.xsl.
  3. Copy the header and foot needed to be valid XSLT into the template.
  4. Try it out on the command line (xsltproc input.xml template.xsl).
  5. Replace data in the example template with the XSLT expressions that replace it with the data from the input.
  6. Repeat from step 4.

XSLT tutorial:
http://www.w3schools.com/xsl/default.asp

Extensions

The libxsl2, used by xsltproc, includes a set of extensions defined in EXSL. Since these are not in the XSLT 1.0 standard they have to be registered explicitly. This is done by putting the name space declarations in the <stylesheet> element:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:math="http://exslt.org/math"
    xmlns:str="http://exslt.org/strings">

The functions defined in those modules can then be called with their name space prefix, like:
<xsl:foreach select="str:split(@ngridk,' ')">
[...]
</xsl:foreach>

For a list of registered functions type

xsltproc --dumpextensions

in the command line.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License