Ionrock Dot Org

by Eric Larson

My Weblog

Cleaning up XML with XSLT

I made a decision the other day that Bright Content would use XSLT for taking ownership of Atom entries. One of the tricky aspects I found was that I essentially wanted to copy the majority of elements in an entry and only add or change a few critical elements such as the atom:id and some of the links. I found this to be a silly problem that required an extremely large amount of code.

My first attempt resulted in a terrible class that included entirely too many lines to simply set the atom:id and add/edit a few links. I would go back and look at the code every now and again an realize how terrible it was, which only made me frustrated to think about fixing it. I saw the light at the end of the tunnel by using a very simple XSLT and creating a few helpful functions that would prove to be helpful outside of the importing use case.

My new issue is how I can make a reusable library of XSLT templates and functions available from a Python module. I did a similar task with a small project at work we called brain. I called the module 'memory' which allowed you to create packages (similar to eggs) that had a file store. It was really nothing more than a module that allowed you to read/write files in folder that was next to an executable (did I mention it was in IronPython...).

I would like to write a simple library that does something similar and then create a simple bit of middleware that provides a RESTful service for the files offered through the library. I am sure none of this is too terribly new, but so far the Python world seems somewhat indifferent to XML and with the advent of eggs it would be nice is including XSLT along with a Python module could prove to be an exceptionally helpful task.

Posted Tue Mar 20 15:10:33 2007 by Eric Larson

Twitter

Links

Reading

Created using Python, jQuery and Emacs