You have to thank the xpath translate function.
While implementing the comments functionality for this blog, I came across the problem of transforming the following data snippet:
<xml>
<comment name="Rhys"
url="http://www.hairy-spider.com/blog">Comment data</comment>
<comment name="Dave"
url="HTTP://www.google.com/">Comment data</comment>
<lcomment name="Pete"
url="www.yahoo.com">Comment data</comment>
</xml>
What I then wanted to do was to write out an A tag with the href set to the url attribute. No the href for the third statement will need an http:// added, so I need to detect if url starts with http:// if so write out that otherwise add an http://.
This is easily achieved with the xsl:if command:
xsl:if test="starts-with(@url,'http://')"
The problem with this is that the starts-with function is case sensitive, and so I had to rely on an old trick involving the translate function and the final statement became
xsl:if test="starts-with(translate(@url, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'http://'))"
It's the first time I've had to use this method in anger, and I'm really pleased with the results. Now I've got half a dozen other ways where I can use this function.