
Question:
Can Saxon map the following extension function call the java static method with varargs below?
<strong>XSLT:</strong>
<xsl:value-of select="mylib:fun('a', 'b', 'c')"/>
<strong>Java</strong>
public static String fun(String arg1, String... args) { ... }
I would expect that saxon supports varargs but, I get
<blockquote>The namespace URI and local name are recognized, but the number of arguments is wrong
</blockquote>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
Answer1:I think you've answered your own question: SAXON does not support it.
Moreover, <em>it makes sense</em> 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'))"/>