Styling XML files

Tuesday 2 December 2003This is 21 years old. Be careful.

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:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
Comment text is Markdown.