Writings

Documents

Weblogs

Documents
Building this Website with XML and XSL
Pages  1  2  3  4 
Overview:  I took on the task of rewriting both my personal and my work/business web site in late January, 2004. The site you are browsing is the outcome of that project. This document is written for people with some programming knowledge who have some experience with the tools and technologies used to "build" web sites. While not too technical, it also avoids explaining things that working programmers would be likely to know anyway. I assume some familiarity with XML, XSL, the concept of "building" a project, etc.  (March 1, 2004)
The 'Build' Process: Java, Ant, Xalan

I use a Java-based tool for directing the transformation of XML to XHTML, and the XSL transformation is applied by a Java XSL tool. However, there are no dependencies with Java for the XSL transformations--I am only using standard XSL. In principle, I should be able to point a browser to the XML and have the XSL transformation take place in the browser, but at least one attempt to do so failed, and so I haven't bothered with it.

So, starting with some XML files, I use a command-line tool called Ant to call the XSL transformation on each on in turn, and dump the output HTML files into a parallel directory structure. Ant is an open source tool typically used for directing a project's build process. It can, for example, only work upon those files that have changed since the last "build". The XSL transformation uses the built-in, default XSL processor bundled with Ant.

There is no magic to this part of the process. However, there are some extra transformations outside of the pages themselves. There is one list of all project files, in XML format. For each file, only the file name is given, as

<file src="local/xml/technote/xml_and_xsl.xml" />
. An XSL transformation opens up each file and creates a second file pulling out the title, topic, key, sequence number, and a resolved (absolute) reference to use when linking to that file in HTML. A second XSL then sorts that output. This "navigation list" is then used as a lookup source when one page tries to link to another using a <link> tag, as well as to look up all the pages related to a topic.

Last, there is one more file maintained manually, namely an XML file listing topics on the web site. This is used to build the high-level navigation links for the site. Currently the topic support is shallow--no nested topics. Each topic can have a short and long name (short used for navigation links), key, and description. The topic list is also used as a lookup (to get the full topic name), and will be used to generate a site map later on.

Summary

That's the basic gist of how this new system works. I realize there are many tools in available to do this sort of thing. But working on it allowed me to brush up my XSL, and I also have full control over my very simple XML system. The entire effort of negotiating the XML and XSL, and not including writing the content and mucking with CSS, probably took three days. It seems, so far, like a worthwhile effort.

Building this Website with XML and XSL