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

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

Hi, David:

  Thanks for some of the clarifications. I think I am still a little puzzled with the new structure you provided with putting the tests outside. I tested one, and got a very bad error message that says:

expected a single value for order expression $d ; found: 1848

I am suspecting that I probably did not do the tests properly. Here is the code of my main function:

declare function local:searchresult($seq as element()*) as element()*
let $search := upper-case(request:get-parameter("search", ""))
let $search2 := request:get-parameter("mydropdown", "")
let $search3 := request:get-parameter("mydropdown2", "")
let $search4 := request:get-parameter("mydropdown3", "")
let $search5 := upper-case(request:get-parameter("search2", ""))
let $search6 := upper-case(request:get-parameter("search3", ""))
let $search7 := request:get-parameter("restriction", "")
let $search8 := request:get-parameter("restriction2", "")

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)],
$e := collection("my")//ad//head[contains(upper-case(.),$search)],
$f := collection("my")//ad//head[contains(upper-case(.),$search5)],
$g := collection("my")//ad/head[contains(upper-case(.),$search6)],
$h := collection("my")//ad//p[contains(upper-case(.),$search6)],
$i:= collection("my")//ad//address[contains(upper-case(.),$search6)]

let $sorted_result:=
for $doc in distinct-values($seq)
order by $doc
return $doc
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 $note := $seq[.=$d][1]/ancestor::ad/descendant::note
let $pb := $seq[.=$d][1]/preceding::pb[1]
order by $d
if (count($sorted_result) lt 1)
<p>Sorry, too many results returned. Please refine your search to have them displayed.</p>
else if (count($sorted_result) gt 200)
<p>Sorry, there are no results retrieved back. Please check for your input. </p>
for $d at $count in $sorted_result
return <div><p>Showing Result: <b>{$count} / {count($sorted_result)}</b></p>
<p style="font-weight:bold">{$head}&#160; {$head2}&#160; {$head3}</p>

As for the distinct-values in my code, I always have the assumption that it has been generating only results with distinct values as long as it is not deep distinct. I didn't realize that it means I am taking in the white spaces. Is there any suggestions you might provide on what function I might have to use here?

As for the point on the masking, do you mean that it would be better if I correct $search to $seq to avoid inaccessibility?

Thanks again for your help.

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

More information about the talk mailing list