Styling XML files

Tuesday 2 December 2003

These days, it's more and more common to find data files and little languages using XML as their representation. It's a reasonable compromise: the developer saves on tokenizing and parsing, and can focus on semantics, but the user has to read and edit XML files. There's no simple fix for the editing problem, but the reading problem can be solved nicely.

Using the same technique that's been going around for styling RSS, you can style any XML file, to present its contents both with more pleasing cosmetics, and with a more usable structure.

Create an XSLT stylesheet that produces the page you'd rather see than the raw XML. Then add a stylesheet processing instruction to the top of the XML file, referencing your stylesheet:

<?xml-stylesheet type="text/xsl" href="props2html.xslt" ?>

Now launching the XML file in a browser will invoke the stylesheet and render the transformed result. The stylesheet doesn't just have to provide nice cosmetics: it's XSLT, so it can arbitrarily transform the file. I recently did this for a hierarchical data file, and the resulting HTML page provided three different views of the data, with cross-referencing links.

Remember, any XML file will do this trick: RSS feeds, Ant files, XML Schema files, XUL files, and so on and so on.

Comments

Add a comment:

name
email
Ignore this:
not displayed and no spam.
Leave this empty:
www
not searched.
 
Name and either email or www are required.
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p><br><pre>.