Extension Functions

As you might guess, an extension function is defined in a piece of code accessed from the XSLT stylesheet. In some cases, that function is written in a scripting language in the stylesheet itself. In those instances, the scripting code is contained in an XML element that is not in the XSLT namespace. In other cases, the function is in a separate file that is loaded by the XSLT processor at runtime. The code for the function might be written in a scripting language or it might be written in a compiled language.

Regardless of how the extension function is written or accessed, you can pass values to the function and the function can return a result. That result can be any of the datatypes supported by XPath. In addition, XSLT processors are free to allow extension functions to return other datatypes, although those other datatypes must be handled by some other function that does return one of XPath’s datatypes.

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.