Use external functions
The XML API allows us to use external functions with XPath, XQuery, and XSLT.
We can define external functions when we want to use operations that are difficult or impossible to express directly by core functions defined in functions and operators, additional functions defined in the XSLT specification, constructor functions named after an atomic type, stylesheet functions defined using xsl:function declaration of XSLT, or user-defined functions in XQuery. Please note that external functions cannot be used to override built-in functions. For example, suppose we are using an external function, my:power(arg1 as xs:double, arg2 as xs:double), to calculate the value of the first argument raised to the power of the second argument; we could write a Java method taking two Java primitive double arguments that performs the calculation. The details of using external functions are presented in separate articles.
Tasks
- Use external functions with XPath.
- Use external functions with XQuery.
- Use external functions with XSLT.
Subtopics
- Use external functions with XPath
When using an XPath expression that uses external functions, declare the function signatures using an XStaticContext instance and supply (or bind) a Java implementation for each function using an XDynamicContext instance.- Use external functions with XQuery
When using an XQuery expression that uses external functions, declare the function signatures either in the XQuery prolog as external functions or using an XStaticContext instance. Supply (or bind) a Java implementation for each function using an XDynamicContext instance.- Use external functions with XSLT
When using an XSLT stylesheet that uses external functions, declare the function signatures using an XStaticContext instance and supply (or bind) a Java implementation for each function using an XDynamicContext instance.
Use external functions with XPath Use external functions with XQuery Use external functions with XSLT