[xquery-talk] Questions on User-Defined Functions

Michael Kay mike at saxonica.com
Sun Feb 24 09:12:06 PST 2008


You've declared the function as expecting a single element named
"statistics" but you are passing it a sequence of elements named "ad". You
could change it to say "$po as element(ad)*" (The * means zero or more). I
assume your function is really doing something more complex than counting
the items in the input; teh actual parameter declaration should be based on
the assumptions that the body of the function needs to make about the input.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: talk-bounces at x-query.com 
> [mailto:talk-bounces at x-query.com] On Behalf Of Wei, Alice J.
> Sent: 24 February 2008 02:51
> To: talk at x-query.com
> Subject: [xquery-talk] Questions on User-Defined Functions
> 
> Hi, XQueriers:
> 
>   I have here one debugging issue here with XQuery using 
> User-Defined Function.
> 
>   This is what I have now:
> 
> declare function local:total($po as element(statistics))
>       as xs:integer {
>    count($po)
> };
> local:total(collection("xmldb:exist://db/my")//ad)
> 
> The error I got is:
> 
> Error while evaluating expression: declare function 
> local:total($po as element(statistics)) as xs:integer { 
> count($po) }; 
> local:total(collection("xmldb:exist://db/cbml")//ad). The 
> actual cardinality for parameter 1 does not match the 
> cardinality declared in the function's signature: 
> local:total($a as element) xs:integer. Expected cardinality: 
> exactly one, got 517. [at line 115, column 21] In call to 
> function: local:total(element) [5:1]
> 
> The code is based on the XQuery of
> 
> <statistics>
> {count(distinct-values((
> fn:collection("xmldb:exist://db/my"))//ad))}
> </statistics>
> 
> which brings the output of  <statistics>229</statistics>
> 
> What have I done wrong here?
> 
>  The other question I have is that since I intend to create a 
> web application out of XQuery, whether or not I should use 
> user-defined functions. Any suggestion is welcome.
> 
> Alice
> ======================================================
> Alice Wei
> MIS 2008
> School of Library and Information Science Indiana University 
> Bloomington ajwei at indiana.edu
> 
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk



More information about the talk mailing list