fn:function-lookup on extension functions with optional arguments

Added by Martin Honnen almost 2 years ago

I have managed to integrate the CoffeeSacks library into my XML Workbench using Saxon-HE 11.3 Java in the backend.

While trying to use the extension functions provided from pure XPath without any namespace declarations present I found that Saxon raises no error on e.g. the expression

function-lookup(QName('',  'grammar-string'), 1)

for the extension function being declared in as having one or two arguments

public class GrammarStringFunction extends CommonDefinition {
    private static final StructuredQName qName =
            new StructuredQName("", "", "grammar-string");
    private URI baseURI = null;

    public GrammarStringFunction(Configuration config, ParserCache cache) {
        super(config, cache);

    public StructuredQName getFunctionQName() {
        return qName;

    public int getMinimumNumberOfArguments() {
        return 1;

    public int getMaximumNumberOfArguments() {
        return 2;

    public SequenceType[] getArgumentTypes() {
        return new SequenceType[]{SequenceType.SINGLE_STRING, SequenceType.OPTIONAL_ITEM};

but in the end returns for that expression a function Q{}grammar-string#2, i.e. a function expecting two arguments, and consequently raises an error when trying to call the function with only one argument e.g.

function-lookup(QName('',  'grammar-string'), 1)("s = 'a', 'b', a'.")


Error(s) during XPath evaluation: Number of arguments required for dynamic call to grammar-string is 2; number supplied = 1

Is that a restriction of function-lookup and dynamic function call with extension functions?

Or should function-lookup(QName('', 'grammar-string'), 1) give me the one argument version?

Or does the extension function need a different implementation to allow the use with function-lookup for both the two and the one argument version?

Replies (2)

RE: fn:function-lookup on extension functions with optional arguments - Added by Martin Honnen almost 2 years ago

The example to call the function should be (to use a valid grammar)

function-lookup(QName('',  'grammar-string'), 1)("s = 'a', 'b', 'a'.")

and not

function-lookup(QName('',  'grammar-string'), 1)("s = 'a', 'b', a'.")

but the question about whether function-lookup(QName('', 'grammar-string'), 1) should return me e.g. the one argument version remains open.


    Please register to reply