问题
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:
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'))"/>
来源:https://stackoverflow.com/questions/26237239/does-saxon-9-supports-java-varargs-in-extension-functions