Template Problems

Many code generation mechanisms use some form of template. Templates are also used in XSL transformations of XML into different output formats. The mechanism shows the same problems like any other template based generation: How much business logic should go into the templates driving the output formatting? A closer look at XSL/XSLT processing shows that the much claimed separation between content and presentation in XML is actually an illusion. Take this example: Certain output elements need a different formatting but there is nothing in the model to drive the translation process. Now you have two choices: either fix it in the stylesheet - thus including business logic there - or fix the model to include a new element or attribute that can drive the transformation. I guess now I understand why there is a thing like processing instructions in XML/SGML (;-).

The template mechanism for code generation is so popular nowadays that it is worth taking a closer look at its problems. Read the critical paper by Terence Parr on keeping templates clean (see Resources)

I am working with a content management team which had used TCL based templates to render XML data. When they moved to an XSL/XSLT based approach they discovered that the effort to transform the TCL templates into XSL had little to do with the actual output formatting. Because TCL is a turing complete language the templates where also used for many quick fixes for output generation which where not based on model information (i.e. not in the XML data).