[xquery-talk] Questions on User-Defined Functions

Wei, Alice J. ajwei at indiana.edu
Sun Feb 24 07:45:35 PST 2008


Dear Michael:

   Nope, all I want is just something simple that can perform

 <statistics>
 {count(distinct-values((
 fn:collection("xmldb:exist://db/my"))//ad))}
 </statistics>

which brings the output of  <statistics>229</statistics>

I modified my code to what you suggested,

declare function local:total($po as element(ad)*)
       as xs:integer {
    count(distinct-values($po))
};
 local:total(collection("xmldb:exist://db/my")//ad)

and it did bring the number 229, which I wanted. However, the number is now in superscript, and I wanted to add the <statistics> tags back in.
Would I need to declare anything else?

I intend to create a web application out of XQuery, and I am not sure if user-defined functions is the way to go.
Any suggestion is welcome.

======================================================
Alice Wei
MIS 2008
School of Library and Information Science
Indiana University Bloomington
ajwei at indiana.edu
________________________________________
From: Michael Kay [mike at saxonica.com]
Sent: Sunday, February 24, 2008 4:12 AM
To: Wei, Alice J.; talk at x-query.com
Subject: RE: [xquery-talk] Questions on User-Defined Functions

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/


======================================================
Alice Wei
MIS 2008
School of Library and Information Science
Indiana University Bloomington
ajwei at indiana.edu



More information about the talk mailing list