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?
@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.
Posted by: dret | Monday, January 12, 2009 at 09:54
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.
Posted by: Ivan Pepelnjak | Sunday, January 11, 2009 at 08:47