Saturday, January 24, 2009

XML + XSLT = XHAPPINESS

I'm looking at changing the templating and display to an XML + XSLT = XHTML system. I think this would make display programming (which I loath) much easier and more flexible for me. The idea is that the views would produce an XML representation of the data that I was sending to the context of django's template, then use XSLT to transform this into the XHTML that gets sent to jquery.

To do this, I need the help of some libraries. Everyone seems to be in agreement that lxml is the best Python xml library, and I will admit it looks pretty easy. Of course, Django has an xml serialization, but that seems to be more for full model objects, which I may or may not need.

However, to get lxml on my mac, I need the newest libxml2 and libxslt. These are C-libraries. Mac ships with them, but they are outdated, which poses a problem because you can't easily install without creating conflicts. As per this blog's suggestion, I tried installing using MacPorts.

Which means I need to install MacPorts. MacPorts is a package installer for the mac. I installed it and had to copy over what was in ~/.profile to ~/.bash_profile since the bash one takes precedence in Terminal. With that done I used MacPorts to install libxslt and lxml. I did this with:
sudo port install libxml2
sudo port install lxslt
sudo port install py25-lxml


I don't know why I've never used a package installer before. I think I tried fink once back when I didn't know what I was doing and screwed stuff up and never went back. It was a long time ago, too. When everyone on a Mac was used to this whole 'NIX thing.

In other news, I probably will miss the Jan.30th deadline. I can't help it if my social life suddenly improves.

No comments: