Began work on utility XSLT functions
XSLT 2.0 brings a lot of extra functionality to the table, and teiJournal will take advantage of it. One obvious step forward is the ability to define your own functions. In many contexts, this is much better than the old method of doing things using named templates, because you can call a function from right inside an XPath expression. We've recently needed some string-manipulation functions, and I'm anticipating the need for many more, so I've started building a utilities.xsl library, which will be released under MPL 1.1 if it ever gets released. Today I coded and tested these functions:
mdh:lastIndexOf, a simple but necessary routine that's missing from XPath 2.0 for some reason.mdh:truncate, a function for truncating a string to a particular maximum length and adding an ellipsis; this also has the an option to trim it back to the last preceding space, so that words are not broken in the middle.mdh:stripLeadingArticle, a function for use in sorting and presenting document titles which have leading articles. For instance, this title:
The Island of Dr. Moreau
might be sorted on the word "Island", and presented like this:
Island of Dr. Moreau, The
The function handles this. I coded it based on the JavaTitleSortComparatorI wrote yesterday; that works fine, but this provides another option in contexts where we might not be able to install our own Java classes under Cocoon. It can also be used for formatting the titles for display, which the sort comparator can't do.
There's a lot to learn in XSLT 2.0, but this is coming along nicely. I still have to trawl through all my other XSLT projects to identify other utility code that could be encapsulated in this way.