Atom to HTML via XSLT

Wednesday, 4 Nov 2009

Note: Atom 0.3 is now deprecated, but I have not updated this transform to support the IETF standard Atom 1.0 format. A new version will likely be derived from the code that drives my weblog rather than this transform. In other words, the code you find here is only of historical interest.

This transform will produce an XHTML page from an Atom feed, as the name suggests. It uses semantic markup as much as its narrow scope allows and marks up non-semantic tags with CSS classes. Entries are sorted by original posting date.

This stylesheet can be imported and used from another stylesheet, so long as you make sure to have a rule that matches the / root element. You can then simply invoke xsl:apply-templates with mode="atom-feed" on any Atom feed element you like. The result will be a <div>-wrapped fragment that can be placed anywhere inside a larger HTML document.

The current version uses EXSLT features extensively to handle all manner of date-related issues as well as to help with the code structure. Therefore you will need an XSLT processor with solid support for these extensions. I use libxslt, but most popular processors should work just as well. If you have any doubts, the EXSLT site lists supporting processors broken down per individual extension function.