This blog uses used a novel approach (I think) in that it is was entirely Atom 1.0 based. There is was no underlying (X)HTML, everything is was Atom (with a hint of XSL). I came to this approach after I figured out that it is silly to serve the same content in multiple formats when one format suffices. Modern browser are perfectly capable of executing XML/XSL that allow for the transformation of the Atom 1.0 feed into XHTML. There’s some nice stuff going, let’s dig into the details (hey I’m a technologist at heart so why not busy myself with the stuff I love).
The main engine is was Pivot, http://www.pivotlog.net (it’s now WordPress). I like Pivot more and more, it doesn’t get in the way and I haven’t had to tweak a single line of code to get where I’m at right now which is frankly amazing to me and a tribute to the design of Pivot.
Pivot creates an Atom output file, index.xml (the filename is configurable in Pivot).
This file is configured as default document via an Apache .htaccess instruction:
DirectoryIndex index.xml
This means your browser gets XML (Atom) served directly when you access http://feedme.mind-it.info/ instead of HTML.
Pivot has several templates available to apply to content output, one of them being an Atom 1.0 template. Due to Pivot’s ingenious templating structure I was able to add an XSL stylesheet to the XML output without a problem:
<?xml-stylesheet type="text/xsl" href="atom"?>
The XSL stylesheet is called atom, I use Apache content negotiation via Multiviews to deliver the correct XSL stylesheet with either application/xhtml+xml or text/html (Internet Explorer) as media format:
Options +Multiviews AddType application/xhtml+xml .xsl+xhtml AddType text/html .xsl+html
The code above basically selects the right atom XSL file based on the capabilities of the browser. If the browser is application/xhtml+xml capable and prefers this media type (via the qs quality factor) the atom.xsl+xhtml file will be served. If on the other hand the browser isn’t willing or capable (think Internet Explorer) it will be served the atom.xsl+html file.
atom.xsl+html:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml">
<xsl:output encoding="utf-8" indent="yes" method="xml" omit-xml-declaration="yes" media-type="text/html" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="DTD/xhtml1-strict.dtd" cdata-section-elements="script style"/> <xsl:include href="main.xml" /> </xsl:stylesheet>
atom.xsl+xhtml:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml"> <xsl:output encoding="utf-8" indent="yes" method="xml" omit-xml-declaration="no" media-type="application/xhtml+xml" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="DTD/xhtml1-strict.dtd" cdata-section-elements="script style"/> <xsl:include href="main.xml" /> </xsl:stylesheet>
The XSL file itself uses an xsl:include to import the main part of the XSL transformation so I can have two relatively small XSL files to support the content negotiation (atom.xsl+html for text/html and atom.xsl+xhtml for application/xhtml+xml).
All looked well but somehow the HTML formatting wasn’t getting through in Mozilla FireFox. No problems in Internet Explorer though, strange … This is the kind of conundrum that can take all day to solve and it did (take a whole day). On the positive side I learned a lot about XSL, CDATA, namespaces and local names but man what an annoying problem. It turns out that Internet Explorer is quite forgiving but Firefox is more strict in copying portions of XML in a different namespace in the result XML tree. The source document is in the Atom 1.0 namespace (http://www.w3.org/2005/Atom) whilst the result document is in the XHTML namespace (http://www.w3.org/1999/xhtml). Firefox will not allow you to do this (as per XSL specification). The solution took ages to find with various sidesteps involving trying to replace the Atom namespace via XSL but the solution turned out to be pretty simple. I just have to add a <div> element with the XHTML namespace to the content element and all is well.
<content type="xhtml" xml:lang="en" xml:base="http://feedme.mind-it.info/pivot/entry.php?id=8"> <div xmlns="http://www.w3.org/1999/xhtml"> .. </div> </content>
Well that’s basically it. I need to change and tweak a lot but the technique described here is basically what drives this feed/site.
BTW if you’re wondering about the layout of the site, I’m not much of a designer so I used a ready made layout from Andreas Viklund. The photo at the top is mine though, I shot it in 2003 in Gyongju (South-Korea).
Welcome to FeedMind, my personal blogging space and ongoing experiment in web technology. I’ve been thinking about doing a blog for years, started several times but never finished anything. This time it looks like I’m going to succeed. I’ll be mainly blogging about ICT Architecture, Information Security and Web Technology in the broadest sense. Once in a while something personal may crop up, it can’t be helped.
I’m quite a practical guy although I do like the saying that “there’s nothing more practical than a good theory”. There’s a lot of opinion floating around that’s propagated by people who obviously haven’t carried any large projects in the real world. There’s a limit to the amount of new technology you can cram into any project and believe you me that five year old technology still counts as new. I hope to add a voice to the chorus that tries to explain that there’s more than one way to do it (although certain problems can have only a limited amount of correct solutions). You see, I’m already being reasonable on the first posting, it’s stronger than myself.
Anyway, hope you like the blog.
Cheers,
Meint
No related posts.
Comments
No one has said anything yet.
Leave a Comment