0
votes

I have an XQuery function.

declare function local:helloWorld($param1 as xs:string, $param2 as xs:string)  as element() {

Now, I want to say if is possible to count the parameters passed to my function.

Is possible?

Thanks in advance

2
Yes, it is possible, and the count is 2. This may not be what you are asking for, so some information on the context would be useful. - Gunther

2 Answers

1
votes

In standard XQuery it is not possible.

However, the next Zorba release (Version 2.0) which will be available very soon will include a library for introspection which exactly does what you want. As an example, on the current svn version of Zorba the following query:

import module namespace sctx = "http://www.zorba-xquery.com/modules/introspection/sctx";

declare function local:helloWorld($param1 as xs:string, $param2 as xs:string)  as xs:string {
  fn:concat($param1, $param2)
};

sctx:function-arguments-count(xs:QName("local:helloWorld"))

will return "2" (as expected). There is also a module to do reflection, so you can build your function calls completely dynamically. But the price you pay is of course, that this code will not be portable to other XQuery engines anymore.

0
votes

There's no function to count the number of parameters passed to a function. The number of parameters is fixed by the function declaration. It can't change depending on the input.

This article explains functions.