While working with a customer recently we wanted to pull items from multiple libraries that were similar in structure to show the current status of documents in an advanced chart. The results of the data were to be shown in columns stacked by status by library.
How to dynamically retrieve the friendly name of the library from each item being returned in the CAPS response? An easy, yet inelegant, method is to add a text column to the libraries that simply defaults to a hard-coded value with the library’s name when a document is added. But, why add something if it is not really needed, and what if you are dealing with more than just a few libraries?
XSLT 2.0 to the rescue. One of the great functions of XSLT 2.0 is the tokenize function. It is pretty easy to use, yet very powerful for a variety of tasks. In this scenario I wanted to grab the name of the library from an item using the “FileDirRef” column and I didn’t want to apply a recursive template or such to get to it. I wanted to keeps things as simple and lightweight as possible. So here it is:
Just tokenize the “@ows_FileDirRef” value from the CAPS response using the “/” as the delimiter and then tell it you want the last value using the predicate filter [last()] on the result.