# Function Call Errors

Wei, Alice J. ajwei at indiana.edu
Mon Feb 25 15:46:23 PST 2008

```Hi, Jonathon:

To answer your question, what I really was hoping to see is something like:

<statistics> Showing Result: 15 / 25</statistics>
<p>Send 75c for your Giant catalog to
To sell your items, send a list of titles, numbers and conditions with a self addressed stamp return envelope for a reply.</p>

Actually, this function I wrote up was based on the XQuery that looks like this:

let \$sorted_result:=
order by \$doc
return \$doc
for \$r at \$count in \$sorted_result
let \$nodes := \$ad[. = \$r][1]
return
<statistics>
Showing Result: {\$count} / {count(\$sorted_result)}
</statistics>
{\$nodes}

My function:

declare function local:distinct(
\$seq as xs:anyAtomicType*)
as xs:anyAtomicType
{
let \$sorted_result:=
for \$doc in distinct-values(\$seq)
order by \$doc
return \$doc
for \$r at \$count in \$sorted_result
let \$nodes := \$seq[. = \$r][1]
return
<statistics>
Showing Result: {\$count} / {count(\$sorted_result)}

return

My biggest confusion right now is how to switch between the two modes, function and the regular XQuery using built in functions so I can use it in web applications.
Have I missed something here?

Alice
======================================================
Alice Wei
MIS 2008
School of Library and Information Science
Indiana University Bloomington
http://x-query.com/mailman/listinfo/talk
________________________________________
From: Jonathan Robie [http://x-query.com/mailman/listinfo/talk]
Sent: Monday, February 25, 2008 3:13 PM
To: Wei, Alice J.
Cc: http://x-query.com/mailman/listinfo/talk
Subject: Re:  Function Call Errors

Wei, Alice J. wrote:
> Dear Jonathon and Michael:
>
>    Thanks for pointing out the mistake, although I am somewhat confused now that I don't need to declare \$count, \$sorted_result and \$doc since they are used within the query.  And, I am surprised that I don't need to declare \$nodes either, or \$r. (I guess I might still have to, because the output is now 'content correct,' but the layout is odd.
>

Hi Alice,

You might want to read a tutorial on the FLWOR expression to be sure you
understand how variables are bound in a FLWOR expression.

Don't declare variables before you bind them in a FLWOR expression,
variables are created and brought into scope when they are bound. These
variables are bound only within the FLWOR expression.

\$count, \$sorted_result, \$doc, \$nodes, and \$r are bound inside the function.

The FLWOR expression that calls the function always calls it with a
single value, because a for clause always binds its variable to a single
value:

return

Within your function, you then call distinct-values on this single value, and sort it, which will always result in the same single value.

> declare function local:distinct(
>      \$seq as xs:anyAtomicType*)
>       as xs:anyAtomicType
>  {
>  let \$sorted_result:=
>  for \$doc in distinct-values(\$seq)
>  order by \$doc
>  return \$doc
>  for \$r at \$count in \$sorted_result
>  let \$nodes := \$seq[. = \$r][1]
>  return
>  <statistics>
>  Showing Result: {\$count} / {count(\$sorted_result)}
>

Because there's a single value, the result will always be 1. What
exactly do you want this function to do?

Jonathan

>
>    This is what I got:
>
>  Showing Result: 1 / 1Passaic Book Center594 Main Ave.Passaic, N.J. 07055
>
>   Apparently, the entire set is returned with 25 results, and it also have the XML tags, but now it appears it is extracting in ways similar to {data(\$nodes)}.
>   Am I missing something here?
>
> Alice
>
> ======================================================
> Alice Wei
> MIS 2008
> School of Library and Information Science
> Indiana University Bloomington
> http://x-query.com/mailman/listinfo/talk
> ________________________________________
> From: Jonathan Robie [http://x-query.com/mailman/listinfo/talk]
> Sent: Monday, February 25, 2008 2:10 PM
> To: Wei, Alice J.
> Cc: http://x-query.com/mailman/listinfo/talk
> Subject: Re:  Function Call Errors
>
> Hi Alice,
>
> The local:distinct() function you declared has 4 parameters. The
> local:distinct() function you called has only one argument, so your
> implementation is looking for a local:distinct() function declared with
> 1 parameter. You have to make your function call match your function
> declaration.
>
> Jonathan
>
> Wei, Alice J. wrote:
>
>> Hi, XQeriers:
>>
>>    I have a piece of code here that I have modified into the following function:
>>
>> declare function local:distinct(
>>      \$seq as xs:anyAtomicType*,
>>      \$sorted_result as xs:integer*,
>>      \$count as xs:integer,
>>      \$doc as xs:anyAtomicType*)
>>      as xs:anyAtomicType
>> {
>> let \$sorted_result:=
>> order by \$doc
>> return \$doc
>> for \$r at \$count in \$sorted_result
>> let \$nodes := \$ad[. = \$r][1]
>> return
>> <statistics>
>> Showing Result: {\$count} / {count(\$sorted_result)}
>> </statistics>
>> {\$nodes}
>> };
>>
>> return
>>
>> This is currently, not working and keeps popping the following error:
>>
>> org.exist.xquery.XPathException: Call to undeclared function: local:distinct [at line 25, column 1]
>>
>> This is based on the XQuery in the following:
>>
>> let \$sorted_result:=
>> order by \$doc
>> return \$doc
>> for \$r at \$count in \$sorted_result
>> let \$nodes := \$ad[. = \$r][1]
>> return
>> <statistics>
>> Showing Result: {\$count} / {count(\$sorted_result)}
>> </statistics>
>> {\$nodes}
>>
>> Can anyone please give me tips on how to fix up the query so that it would generate something like
>>
>> <statistics> Showing Result: 1 /1</statistics>
>> <p>A business so big growing so fast, you need an appointment in most auto trim shops! Send for FREE MASTER PLAN, ILLUSTRATED BOOKLET on learning auto upholstery and interior customizing in your spare hours. No experience needed. Yet approved auto upholstery institute, dept.
>> </p>
>>
>> Thanks to those who can help.
>> Of anyone on the list who know any resources on where I can practice user-defined function call using interactive tabs woulld be great.
>>
>> ======================================================
>> 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!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format