Ionrock Dot Org

by Eric Larson

My Weblog

Creating a Resolver for Tranformations

The other day I spent a bit of time getting a resolver working for 4Suite and my XSLTemplates library. I am pretty sure the concept of a resolver is in the XSLT spec, but it might not be as it seems the implementations/examples rarely mention them. The idea is that you can resolve links yourself in XSLT. This alludes to the XInclude spec but really is a bit more magic. The resolver can lookup where the requested resource is and grab it. Really it is a pretty simple concept.

The problem is that implementing a resolver is less than intuitive. In .NET my understanding is there is a specific XmlUriResolver class that must be extended in order to create a custom resolver. I haven’t looked into what it takes for something like libxslt2 (which would impact lxml) or saxon. 4Suite handles the resolution when creating an InputSource which is essentially just a wrapper for objects getting passed into different 4Suite objects and methods.

Part of the reason I think resolvers are not very wide spread (from what I have seen at least) is because most folks just don’t think about the functionality. I wanted a resolver in order to allow an external tool to transparently find packages via web requests, local template directories and using data files in eggs via pkg_resources. We use a resolver at my job to do a cascade of lookups so you can override different XSLT files at runtime.

The one caveat regarding a resolver is that it adds a bit of magic to your XSLTs in that a simple URI could be referencing a file anywhere. This could make debugging an issue if someone didn’t understand there was a custom resolver in play. With that said, it is a pretty slick tool to have around. I’ll be adding my new template resolver in my XSLTemplates module, which might help to provide a good example.

Posted Wed Aug 15 15:42:44 2007 by Eric Larson
using python, jquery and emacs ;)