Saturday, November 17th, 2012

In Process of converting PythonDiary to XSLT

I am currently experimenting with converting this blog website over to an entire XSLT compliant website, where each page sent to the browser is nothing more than a simple XML document with a XSLT stylesheet tag. I am not too sure how this will affect SEO or how Google bot crawls through pure xml documents, or even if Google bot is XSLT compliant. Chrome was since version 1, so I am only hoping that Google bot can parse these documents too.

So far, I have been able to convert the What's New page over to a full XML document rendered with XSLT. This change is not yet live and won't be for another few days, as I need to complete the rest of the website first.

Basically, the main Django base.html file will live in a new file called template.xsl, which the browser reads in to render the XML document. The XML document will be a simple rendering of the Context. I plan on using very common tags in the XML documents, such as title, script, and body. The XML document will take full advantage of XML attributes to relay special information such as permalinks and links to tags.

The only real problem I am seeing is that these articles contain HTML, and XML/XSLT don't play well with XML files that contain HTML, and won't render their tags in the browser at all. So, I will need to make sure these tags are added to the XSLT document in order for them to render correctly. For the most part this shouldn't be a problem with a few template match tags.

In the end, this will make this entire blog immediately compatible with third party applications and tools. This includes the possibility for a future mobile app. Every modern browser has the ability to directly render XSLT, so moving my front-end development efforts to this technology seems logically. It will future proof any website automatically, giving every content page an XML document regardless if it is requested or not. This may also deter comment spammers as well, since the document being served is a pure XML document with no FORM tags whatsoever. The XSLT template will handle all the rendering of the comments form and the comments themselves.

Please note that server-side XSLT will not be used, and that the site will be using the client-side XSLT. In this day and age, I expect everyone to be using a browser which natively supports XSLT. To test your browser for this support, visit this website, which is rendered using a pure XML document. In a compliant browser, it will render a proper HTML table. However, since the XML documents I will be building will use standard HTML tags, if your browser isn't compliant, you should still be-able to view a style-less version of the article. Again, every modern browser supports this, so I don't see moving to a XML/XSLT solution being an issue for any of the readers here.

As for the mobile app comment above, Android natively supports XML parsing and provides many examples of it's use. I plan on taking advantage of this when I build a mobile app for PythonDiary in the coming months.

If successful, I plan on releasing an XSLT bootstrap template which will work with any client/server-side framework regardless of language. The placeholders will be simple XML tags, and every server-side language can generate XML documents in one form or another. Personally, I'd love if template authors took on XSLT and sold templates in this form, since it's universally compatible. Rather these authors are instead building templates specific to web framework, and it's difficult to port over to your framework of choice. XSLT seriously needs to be looked at by template authors looking for a cross-framework solution.

Comment #1: Posted 1 year, 5 months ago by Anonymous

Have you considered using an alternative template generator?

Django is not focused on structured document generation ().

But Genshi is.

Also, you can use it to generate XML+XLST > XHTML compatible content. This will solve the XML+XLST delayed implement gap. XHTML is also a XML document, so your content can act as a machine-readable document. I think is easier to switch to another template generator or event framework.

Trying to force Django to make not intended things usually ends in lots of crappy code.

PS: Increase your auth token expiration. Comments than require more than 10 minutes to write are normally interesting.

About Me

My Photo
Names Kevin, hugely into UNIX technologies, not just Linux. I've dabbled with the demons, played with the Sun, and now with the Penguins.

Kevin Veroneau Consulting Services
Do you require the services of a Django contractor? Do you need both a website and hosting services? Perhaps I can help.

If you like what you read, please consider donating to help with hosting costs, and to fund future books to review.

Python Powered | © 2012-2013 Kevin Veroneau