|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] Questions on User-Defined FunctionsMichael Kay mike at saxonica.comSun 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: http://x-query.com/mailman/listinfo/talk
> [mailto:http://x-query.com/mailman/listinfo/talk] On Behalf Of Wei, Alice J.
> Sent: 24 February 2008 02:51
> To: http://x-query.com/mailman/listinfo/talk
> Subject: 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 http://x-query.com/mailman/listinfo/talk
>
> _______________________________________________
> http://x-query.com/mailman/listinfo/talk
> http://x-query.com/mailman/listinfo/talk
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






