[xquery-talk] If Statements within an If Statement?

Wei, Alice J. ajwei at indiana.edu
Wed Apr 2 09:19:38 PST 2008

Hi, XQueriers:

   This may be a simple problem, but it appears that I have either missed something or have problems figuring out what a certain function means.

Here is my function:

declare function local:searchresult($seq as element()*) as element()*

let $a := collection("my")//ad//address[contains(upper-case(.),$search)],
$b := collection("my")//ad//p[contains(upper-case(.),$search)],
$c := collection("my")//ad//address[contains(upper-case(.),$search5)],
$d := collection("my")//ad//p[contains(upper-case(.),$search5)]

let $sorted_result:=
for $doc in distinct-values($seq)
order by $doc
return $doc
for $d at $count in $sorted_result
let $head := $seq[.=$d][1]/ancestor::ad//child::head[1]
let $head2 := $seq[.=$d][1]/ancestor::ad//child::head[2]
let $head3 := $seq[.=$d][1]/ancestor::ad//child::head[3]
let $para := $seq[.=$d][1]/ancestor::ad//child::p
order by $d
<div><p>Showing Result: <b>{$count} / {count($sorted_result)}</b></p>
<p style="font-weight:bold">{$head}&#160; {$head2}&#160; {$head3}</p>
local:searchresult($a union $d

I would like to have this so that it can say something like


if (count($sorted_result) lt 1)
then <p>Sorry, no results retrieved.</p>
else if (count($sorted_result) gt 200)
then <p>Sorry, too many results returned.</p>
<div><p>Showing Result: <b>{$count} / {count($sorted_result)}</b></p>
<p style="font-weight:bold">{$head}&#160; {$head2}&#160; {$head3}</p>

My problem is

(1) When I tried to do a count of the result in the first if statement, it does not even show anything. (Is this another XPath problem?)
(2) Is this syntax accurate?

Any suggestion is appreciated.

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

More information about the talk mailing list