XProc extension functions

Volume 16, Issue 8; 20 Aug 2013

User-defined functions are a valuable extension mechanism. They allow us to modularize, reuse, and generally simplify otherwise complex expressions. Wouldn't they be nice in XProc pipelines?

What happened was, a friend of mine asked if it would be possible to have some RDFAa-related extension functions in XProc. He'd defined them in XSLT and devised a clever, if cumbersome, mechanism for invoking them with the p:xslt step.

I thought, sure, I could add those as extension functions. Then I saw that they were in a private namespace and weren't general-purpose functions so much as application-specific functions. My enthusiasm for banging them out in Java and putting them in XML Calabash waned quickly.

What I thought would be really cool would be to define them in XQuery (or XSLT) and simply import them into the pipeline. Then you could make up functions at will and use them.

So that's what I did. (Special shout out to Michael Kay for pointing me through the trail of API calls necessary to make this work.)

Caveats:

  • Using this feature makes XML Calabash non-conformant and, consequently, makes your pipeline processor-dependent. Not ideal, but maybe this is a feature that can be standardized if it's popular.

  • It requires Saxon EE. Nothing I can do about that.

  • There's no scoping. All of the loaded functions go into the single Processor object. This means you can import them in one pipeline and use them in another which is ugly.

Share and enjoy.

Comments on this posting are closed. Thank you, spammers.