[xquery-talk] If Statements within an If Statement?
Wei, Alice J.
ajwei at indiana.edu
Wed Apr 2 16:59:05 PST 2008
Hi, David and Michael:
What is interesting is that when I put only one function out as I have had before, it brings me the appropriate result from the return.
Currently, I have many similar patterns of such function, only its element calls may be different (which was why I ran into problems with union and intersect operators)
If I modify my function call to this, then the problems of why I started posting here reappear.
declare function local:main($search as xs:anyAtomicType*) as element()*
{
let $a := collection("my")//ad//address[contains(upper-case(.),'BOY')],
$b := collection("xmldb:exist://db/cbml")//ad//p[contains(upper-case(.),'GIRL')]
return
local:searchresult(($a union $b) intersect ($a except $b))
};
declare function local:searchresult($seq as element()*) as element()*
{
let $a := collection("my")//ad//address[contains(upper-case(.),'BOY')],
$b := collection("my")//ad//p[contains(upper-case(.),'GIRL')]
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/descendant::head[1]
let $head2 := $seq[.=$d][1]/ancestor::ad/descendant::head[2]
let $head3 := $seq[.=$d][1]/ancestor::ad/descendant::head[3]
let $para := $seq[.=$d][1]/ancestor::ad/descendant::p
let $pb := $seq[.=$d][1]/preceding::pb[1]
order by $d
return
if (count($sorted_result) lt 1)
then
<p>Sorry, too many results returned. Please refine your search to have them displayed.</p>
else if (count($sorted_result) gt 200)
then
<p>Sorry, there are no results retrieved back. Please check for your input. </p>
else
<div>
<p>Showing Result: <b>{$count} / {count($sorted_result)}</b></p>
<p style="font-weight:bold">{$head}  {$head2}  {$head3}</p>
<p>{$para}</p>
</div>
};
let $a := collection("my")//ad//address[contains(upper-case(.),'BOY')],
$b := collection("my")//ad//p[contains(upper-case(.),'GIRL')]
return
local:main(collection(my")//ad)
The number of results got returned is 0, which is accurate, but it does not give me any output of what I have had here:
if (count($sorted_result) lt 1)
then
<p>Sorry, too many results returned. Please refine your search to have them displayed.</p>
Is this something I should be doing? Or, is there some syntax errors I have here?
Thanks again for your help.
Alice
======================================================
Alice Wei
MIS 2008
School of Library and Information Science
Indiana University Bloomington
ajwei at indiana.edu
More information about the talk
mailing list