xpath.ExternalFunctionObject¶
The xpath.ExternalFunctionObject is the base class for native extension functions.
Provides the function signature and the on_invoke callback method.
Validated and aggregated in the xpath.ExternalFunctions.create() method.
# An example extension function:
# -----------------------------
# Step 1: Derive from xpath.ExternalFunctionObject
class FunctionWithNativeCallback(xpath.ExternalFunctionObject):
'''
An native extension function for the transformation engine
providing implementation for the on_invoke method.
'''
def __init__(self):
# Step 2: Initialize the base class with the function signature.
super().__init__("Q{native-python-extension-functions}lorem($arg1 as xs:string) as xs:string")
# Step 3: Implement the on_invoke method.
def on_invoke(
self,
param_list: List[xpath.Sequence],
session: xpath.Session,
called_by: xpath.Instruction
) -> xpath.Sequence:
# Note: param_list contains the current arguments
# and can be None for 0 arity functions.
val = "lorem ipsum: "
val += str(param_list[0][0])
str_item = xpath.AtomicItem.create_from_string(val, session)
return xpath.Sequence.create_from_item(str_item)
# Step 4.Create a function library and set it on the compile options.
fn_lib, log = xpath.ExternalFunctions.create(session, FunctionWithNativeCallback())
- class xpath.ExternalFunctionObject(unicode signature)¶
The signature must match the grammar:
EQName “(” ParamList? “)” ( “as” SequenceType )?
The function name, parameter count, and the optional argument and return types will be inferred from the signature.
Attributes¶
- xpath.ExternalFunctionObject.signature¶
Methods¶
- xpath.ExternalFunctionObject.on_invoke(param_list, Session session, called_by)¶
For xpath function calls, override and implement the on_invoke callback method. The param_list provides position based access to the
xpath.Sequencevalues of the function arguments. The returnedxpath.Sequenceis propagated to the executing expression.def on_invoke( self, param_list: List[
xpath.Sequence], session:xpath.Session, called_by:xpath.Instruction) ->xpath.Sequence:Note: the engine performs the implicit XPath type conversions on the param_list and on the returned sequence.
Arguments: param_list – a list of
xpath.Sequence, the current argument values. session – thexpath.Session. called_by – anxpath.Instructionproviding location information.Returns:
xpath.Sequence
Special methods¶
__eq__, __ge__, __gt__, __le__, __lt__, __ne__