« Robots take over Science! | Main | More Short Reviews »

Tuesday, January 06, 2009

MD5 in XSLT

i recently started wondering how hard it would be to implement MD5 in XSLT. googling did not turn up anything other than pages saying that your XSLT processor should have an extension function for that. in this list of MD5 implementations (which may be incomplete, of course), nothing showed up.

the algorithm itself is not too complicated, but it involves a lot of bit shifting, which does not work all too well in XSLT. so i am wondering whether the algorithm should be implemented with numbers and arithmetic operators as provided by XSLT, or on strings, treating everything as bit strings. this latter approach probably would become very inefficient rather quickly, i am afraid (inputs to MD5 can be arbitrarily large).

another issue might be that the recursive nature of XSLT might make the implementation prone to heap space problems. i have a number of functions doing fairly trivial things, but with big enough inputs, they all produce heap space errors and have to be invoked with more-than-normal heap space (i use Saxon and Java provides easy control over these parameters when starting the JVM).

which makes me wonder: if you have XSLT code that is prone to very deep nesting, and you are not using a Java-based XSLT implementation, will that generally lead to your XSLT code crashing? or are other implementations and their execution environments less prone to hard limits and will dynamically allocate as much heap space as required?

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

@ivan: thanks for the comment. i don't care so much about browser support. for anything a little bit more complicated XSLT 2.0, and in particular XPath 2.0, is such a big advantage over the 1.0 versions that i am really preferring the new versions. and i am doing server-side programming anyway.

but i don't want to start developing code that depends on a particular XSLT implementation. and i am not even sure there is an EXSLT for XSLT 2.0 for community consensus around extension functions. but even if there was one, i'd prefer to have an XSLT implementation of MD5, so that code could run on any XSLT processor.

The arithmetic and string function support in XSLT 1.0 is so basic that I have problems implementing obvious things, let alone MD. XSLT 2.0 might be different, but I will not touch it until it gets significant browser-side support.

If you're using Saxon, it should not be too hard to implement an extension in Java.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Flickr

Twitter Updates

    follow me on Twitter