Encode project knowledge in XML

I went and sat and read the XSLT cookbook again. This time I read a bit about SVG but also the introduction to the chapter on code generation. The gist of it was that by encoding project knowledge in XML (or something similar) and using XSLT (or similar) to generate implementation files (of any form) you can adapt to changes in that source knowledge easily.

For example, I’m asked to build a website and as part of the design we decide to put tabs across the top of the page to link to the main areas of the site. When we begin the project we agree on six areas, but as I build the site I notice that two areas could be merged into one. Instead of having to change every page I’ve made so far (by hand or by Perl), I just tweak my knowledge file and set my stylesheets loose on it again.

I was discussing code generation with Miles recently and he raised the points that edge cases easily throw big spanners into the process and fixing these situations after the generation puts you at risk of regression errors. The knowledge encoding should be flexible enough to allow the author to identify edge cases (by some kind of pattern recognition most likely) and provide additional information that allows the transformation process to avoid making errors. Even if that is as simple as being able to include Ant tasks that use Perl or other external software to hack the implementation outputs.

I did try something similar once. WEBWAX was a system where you created a knowledge file for a website, that would be converted into the output site by XSLT. It worked quite well, but it was a bit inelegant. Having learned much more about XSLT since then and also having become familiar with Ant, I know I could write a much better system.

XML and XSLT are a great system for encoding knowledge and generating outputs because they have powerful friends. A knowledge file might be transformed into an Ant build file and a set of other XML documents. The Ant build process can perform a lot of work, moving files, running programs or even performing further transformations. Or the stylesheet could generate SVG so that you can create diagrams and graphics for documentation purposes. A website map could be generated easily in this way, as could ERDs for an application. XSLT can output any kind of text as well, plain text ain’t going out of fashion and it’s a route into many many systems.