XPointer Framework for XSLT 2.0
In a recent project I found myself needing more flexibility when cross-referencing XML content during XSLT transformations. The XSLT 2.0 specification (as implemented by Michael Kay) only includes shorthand XPointers. So this seemed a good opportunity to write a more complete implementation of the XPointer Framework for Michael Kay’s fantastic Saxon processor.
Essentially, XPointer allows one to reference a fragment of a resource (as opposed to the entire resource):
<!-- Shorthand XPointer: Locate a customer using the @xml:id attribute. -->
<order customer="customers.xml#cust001"/>
<!-- Element Scheme: First customer in an element where @xml:id="customers". -->
<order customer="customers.xml#element(customers/1)"/>
My implementation of this includes support for the standard xmlns() and element() schemes, and additionally the xmlns-local(), xpath1() and xpath2() schemes. This implementation, however, does not yet include the xpointer() scheme.
Additional schemes can be implemented by providing a custom template. The template will be invoked automatically by the XPointer framework stylesheet when the scheme is detected in a URI upon lookup. Custom schemes should be qualified with a namespace so as to avoid conflicts unless implementing a standardized scheme.
I have made the stylesheet (and some examples) freely available under the BSD license.
Check out http://www.rotorz.com/xml/2009/XPointer for more information and downloads.