DIY functions in XSLT 2.0

Functions? Do It Yourself. You can DIY functions with XSLT 2.0.

An example

Here's some XML for William Shakespare's The Tragedy of Hamlet, Prince of Denmark, Act 3, Scene 1.

Click here to see the XML document for this play.

Here's a transform that's got a couple of functions.

  • substr gets a substring of length len from a string str, but only breaking on a word boundary delimiter like ,."!?().
  • reverse reverses the words in a string str.

And here's the very useful output!