Discover functions at runtime
Added by Morten Wittrock about 7 years ago
Hi everybody
Not sure whether this is possible, but here goes: Given a function namespace, like saxon:, is it possible to iterate over the functions in that namespace in a stylesheet, retrieving metadata like function name, parameters etc.?
Regards,
Morten Wittrock
Replies (2)
RE: Discover functions at runtime - Added by Michael Kay about 7 years ago
You can discover whether a particular function exists by using function-lookup(), but there's no general capability to discover all functions in a namespace. In some cases the number of functions is infinite (e.g. variants of the concat function).
Internally functions are organised into FunctionLibrary objects, and for built-in functions (in 9.8) the FunctionLibrary is usually implemented as an instance of BuiltInFunctionSet. If you really want to drill down into internals you can use reflexion to access the functionTable field in a BuiltInFunctionSet, which is a hash table having keys in the form localname#arity.
It's not the case that all functions are implemented this way. For example some of the functions in the Saxon namespace are still implemented using Java reflexion in the class com.saxonica.functions.extfn.Extensions, and a variety of implementation techniques are used for the various EXPath and EXSLT libraries.
RE: Discover functions at runtime - Added by Morten Wittrock almost 7 years ago
Hi Michael
Thank you so much for your reply.
Regards,
Morten
Please register to reply