Pretty-Printing XML with XSL

One of the things I really enjoy about my job is that as the only developer on my project (formerly known as λ, now officially named Kinerja), I get to tackle a bunch of different types of programming jobs.  Working on the model checking core is pretty different from working on the web interface, and neither of those are at all similar to tuning the database backend.  Though the (vast) majority of my work is in Java, other layers are written in their own language (PHP, SQL, etc.).  One of the most exciting parts of my job, then, is to learn a new technology to handle a new aspect of the project.

Since Kinerja's input files are in the XML format produced by YAWL's user-interface, we don't have a lot of flexibility with making those look the way we'd prefer.  Though my adviser and I have talked about coming up with our own domain-specific language, it's hard to imagine one that would be less bulky than YAWL's XML that would still support all of its features.  That said, we still wanted a way to look at a workflow without firing up the user-interface and manually inspecting the intricacies of each workflow-task.  We decided, then, to write a simple formatter.  Since we were modifiying an XML file, I decided to learn and use XSL (eXtensible Stylesheet Language) — specifically XSLT (the T stands for transformations, in my case from XML to HTML).

XSLT is a declarative language (or a language where the control-flow is not explicitly stated) and it's the first time I've used such a language.  It took a little while to get used to (and plenty of example-reading) but I think I'm pretty much up to speed now.  So far, I've created a number of small examples (in XSLT) and a full-scale mockup (in hard-coded HTML).  My project for the coming week is to make the actual pretty-printer, and I'm interested to see how it will turn out.  It uses a number of different XML files (with values in one referencing values in the other) so it should be quite the task.

I didn't choose to use XSL simply because it was a new technology, however, but also because it has a number of really beneficial qualities.  The first is that it's usable (nearly) anywhere.  Not only can it be rendered server-side (via another language, like PHP's XML package, or Java's XALAN) but it's also one of the (relatively) few technologies that can be used client-side as well.  In fact, you can have web-page visitors do a great deal of formatting work themselves by giving them XML and and XSL stylesheet.  Indeed, this was my original plan, however some less full-featured browsers (e.g.: those running on mobile phones) aren't as reliable as the major computer-based browsers.  Still, the fact that this formatter won't have to be re-written even if the rest of the server code would be (if it gets re-based to Java, for example) is an interesting (and somewhat comforting) thought.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.