Vitavonni

Wed, 15 Feb 2006

When XSLT gets really messy...

XSLT is an outright ugly language. Thats why I often just hate it. In some (rare) cases it's very elegant, but most often incredibly clumsy.

I've been redoing my homepage completely, and I'm using XSLT to render my data XML files to the XHTML output. That works quite well so far, but I hit more and more special cases.

First I wanted to add a language chooser. This required finding out which lanuages my document supports (read: blocks with that language attribute exist) and check for uniqueness.

Some things where rather easy to solve (with some experience in XSLT), so where extremely ugly.

First of all, I want my template file to be a valid XHTML file, I don't want to have any layout parts in XSLT. Then I have a separate sitemap, needed for generating the menu. So I have to process three documents at the same time in XSLT. Ouch. But doable, using variables.

Basically I have three modes - in one mode, the template is mostly copied over, unless I've specified some special rule, e.g. to insert the page title, meta information or content. A second mode uses the current chunk of the template document as template for the contents a couple of times to iterate over data chunks from the data source file (read: put text blocks from my source files into the output template format). The third mode does the same for the sitemap.

Unfortunately, it started to get even messier...

Big problem number one: Make a list of the available languages for the current page. Make this information reuseable throughout the page transformation. Part one: make a list of available languages by finding unique (!) @lang attributes. (usual approach: grab all nodes with @lang attributes, check if they have the same node id like the first occurence with this @lang value for uniquness, then output. Ugly as hell, but string magic sucks as much.)

Big issue number two: Assume we now have a variable with en in there, access these nodes to transform them. Unfortunately, the generated nodes are "result nodes", and you cannot iterate over them with for-each. Luckily the exslt node-set extension to solve this.

But now came the third big issue along... this is where I give up. I want my pages to have a nice modification date... my data pages are stored in subversion... Subversion has keywords expansion like CVS, which I can use nicely to automatically update the last modification date of the file. Unfortunately, the date will look like this:

$Date: 2006-02-15 21:29:10 +0100 (Mi, 15 Feb 2006) $

Whereas in a web page meta information it's recommended to use ISO8601.

Now if I only had regular expressions and proper date handling functions...

I guess I'll stop writing ugly, hackish XSLT code and chose pretty Python code instead. Maybe use TAL or KID for XMLish templating...

[category: /en/xml | Permalink]
Menu
[planet.debian]
[planet.xmlhack]
[planet SELinux]
[munichblogs]
[email]
[RSS 2 feed]
[English RSS 2]
Categories
< February 2006 >
SuMoTuWeThFrSa
    1 2 3 4
5 6 7 8 91011
12131415161718
19202122232425
262728    
Archives
2010-Mar
2010-Feb
2010-Jan
2009-Dec
2009-Nov
2009-Oct
2009-Sep
2009-Aug
2009-Jul
2009-Jun
2009-May
2009-Apr
2009-Mar
2009-Feb
2009-Jan
2008-Dec
2008-Nov
2008-Oct
2008-Sep
2008-Aug
2008-Jul
2008-May
2008-Apr
2008-Mar
2008-Feb
2008-Jan
2007-Dec
2007-Nov
2007-Oct
2007-Sep
2007-Aug
2007-Jul
2007-Jun
2007-May
2007-Apr
2007-Mar
2007-Feb
2007-Jan
2006-Dec
2006-Nov
2006-Oct
2006-Sep
2006-Aug
2006-Jul
2006-Jun
2006-May
2006-Apr
2006-Mar
2006-Feb
2006-Jan
2005-Dec
2005-Nov
2005-Oct
2005-Sep
2005-Aug
2005-Jul
2005-Jun
2005-May
2005-Apr
2005-Mar
2005-Feb
2005-Jan
2004-Dec
2004-Nov
2004-Oct
2004-Sep
2004-Aug
2004-Jul
Other links:
Swing and the City - Lindy Hop in Munich