devxlogo

XmlTransform—A General-Purpose XSLT Pre-Processor

XmlTransform—A General-Purpose XSLT Pre-Processor

he general-purpose XML transformer and/or validator discussed here, named “XmlTransform” operates on an arbitrarily deep directory tree containing files you want to transform. As output it optionally generates multi-level indices and can even add navigational linkages.

XmlTransform’s validation capability is reasonably straightforward; it lets you ensure that the set of XML files used for a transformation are valid according to specified XML schema. You may elect to validate input files, output files (after transformation), or both.

The program’s transformation capability is more interesting. One common application of a transformation engine is as a pre-processor, a very handy thing indeed when designing web pages.

Pre-Processors and HTML
Modern, well-formed HTML is a flavor of XML called “XHTML,” which has subtle but important differences from plain HTML. XmlTransform can transform XML files to web pages quite effectively. In fact, it can generate any arbitrary XML output that you tell it to, but because the process is easier to visualize with a concrete file type such as HTML that you probably already know, the discussion here focuses on HTML generation.

So what is a pre-processor and why is it useful? Maintenance is the primary resource consumer on any software project—often requiring more resources than the original design and implementation of the project. A pre-processor can help reduce maintenance costs. For example, assume that you maintain a corporate web site that displays a logo of a certain size on every one of its 509 plain-vanilla HTML pages. If the corporation suddenly decides to get a new look—new letterhead, new typefaces, and oh, yes, a new, differently sized logo, you would need to edit each of the 500+ pages to display the new logo image. While the amount of work involved in such a change might vary, depending on how the pages are set up, the point is that changes do occur that cause frequently occurring web page elements page to need periodic updating.

That’s where pre-processors come in. Just like a style sheet lets you define something once and reuse it over and over, a pre-processor does the same thing for anything in your web pages, not just styles. You could, for example, create your own XML