Does Saxon 9 supports java varargs in extension functions?

倾然丶 夕夏残阳落幕 提交于 2019-12-13 05:02:03

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!