0
votes

Can Saxon map the following extension function call the java static method with varargs below?

XSLT:

<xsl:value-of select="mylib:fun('a', 'b', 'c')"/>

Java

public static String fun(String arg1, String... args) { ... }

I would expect that saxon supports varargs but, I get

The namespace URI and local name are recognized, but the number of arguments is wrong

Am I doing something wrong?

It seems it's able to recognize a sequence () but I want to implement a function with zero or more arguments like those that are in the standard XPath function library.

Thank you

1
Actually, there's only one variable-arity function in the standard XPath library, concat(), and that's something of an anomaly. Generally the XPath philosophy is that a function is identified by its name and arity, and varargs doesn't fit well into that thinking.Michael Kay

1 Answers

0
votes

I think you've answered your own question: SAXON does not support it.

Moreover, it makes sense that SAXON does not support it. Java varargs are implemented in the compiler; they are not represented in class files or bytecode. All SAXON sees is a method accepting two arguments (a String and a String[]) and returning a String.

I'm not familiar with all the details of SAXON's type mapping, but perhaps you could achieve your objective by passing a list as the second function argument:

<xsl:value-of select="mylib:fun('a', ('b', 'c'))"/>