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

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


Hi, David:

  To answer your question, the reason why I am putting everything in here is because I am reusing this as a kind of template.If the result today is more than 200, I would expect it to give the output of saying there are too many results and not no results.

  The $search, is there because I am using this from the web, so when I run the code, the line

   let $search := upper-case(request:get-parameter("search", ""))

will be in the code to run online. I took those out since I have provided the terms to search to show you the output.


declare function local:main($search as xs:anyAtomicType*) as element()*
{
let $search := upper-case(request:get-parameter("search", ""))
let $a :=       <ad xml:id="ad120" n="Killer Shark" corresp="bibl01">
                    <head>Killer Shark</head>
                    <p>Shock and surprise your friends with this huge 6 sq. ft. SHARK POSTER. Full
                        color. Live action shark attack tearing a human to pieces. Hurry. Send $3.95
                        to "WHITE MAKO."
                        <address><addressLine>1505 Aviation Blvd,</addressLine>                            <addressLine>Redondo Beach,</addressLine>                            <addressLine>Ca. 90278</addressLine>                        </address>10
                        day money back guarantee. WARNING! NOT FOR SISSIES! </p>
                </ad>,
$b := <ad xml:id="ad123" n="Are You Unlucky?" corresp="bibl01">
                    <head type="main"> Are You Unlucky? </head>
                    <head type="sub">Gene will change your luck!</head>
                    <p>Aladdin's Own Lucky Gene cast from the ancient origina. 4K gleaming Gold
                        plate. Famous for good luck. Rub him. He's yours to command. Try
                        him&#8212;See your LUCK improve or your money back. Free history. Free
                        lucky. Book &amp; famous good luk prayer. No C.O.D.'s.
                        <address><addressLine>Advance Merchandise Corporation of America</addressLine>                            <addressLine>Box 617, Dept. MM</addressLine>                            <addressLine>Lynbrook, N.Y. 11563</addressLine></address>
                    </p>
                </ad>

return
local:searchresult($a union $b)

};

declare function local:searchresult($seq as element()*) as element()*
{
let $a :=       <ad xml:id="ad120" n="Killer Shark" corresp="bibl01">
                    <head>Killer Shark</head>
                    <p>Shock and surprise your friends with this huge 6 sq. ft. SHARK POSTER. Full
                        color. Live action shark attack tearing a human to pieces. Hurry. Send $3.95
                        to "WHITE MAKO."
                        <address><addressLine>1505 Aviation Blvd,</addressLine>                            <addressLine>Redondo Beach,</addressLine>                            <addressLine>Ca. 90278</addressLine>                        </address>10
                        day money back guarantee. WARNING! NOT FOR SISSIES! </p>
                </ad>,
$b := <ad xml:id="ad123" n="Are You Unlucky?" corresp="bibl01">
                    <head type="main"> Are You Unlucky? </head>
                    <head type="sub">Gene will change your luck!</head>
                    <p>Aladdin's Own Lucky Gene cast from the ancient origina. 4K gleaming Gold
                        plate. Famous for good luck. Rub him. He's yours to command. Try
                        him&#8212;See your LUCK improve or your money back. Free history. Free
                        lucky. Book &amp; famous good luk prayer. No C.O.D.'s.
                        <address><addressLine>Advance Merchandise Corporation of America</addressLine>                            <addressLine>Box 617, Dept. MM</addressLine>                            <addressLine>Lynbrook, N.Y. 11563</addressLine></address>
                    </p>
                </ad>

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]
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}&#160; {$head2}&#160; {$head3}</p>
<p>{$para}</p>
</div>
};

let $a :=       <ad xml:id="ad120" n="Killer Shark" corresp="bibl01">
                    <head>Killer Shark</head>
                    <p>Shock and surprise your friends with this huge 6 sq. ft. SHARK POSTER. Full
                        color. Live action shark attack tearing a human to pieces. Hurry. Send $3.95
                        to "WHITE MAKO."
                        <address><addressLine>1505 Aviation Blvd,</addressLine>                            <addressLine>Redondo Beach,</addressLine>                            <addressLine>Ca. 90278</addressLine>                        </address>10
                        day money back guarantee. WARNING! NOT FOR SISSIES! </p>
                </ad>,
$b := <ad xml:id="ad123" n="Are You Unlucky?" corresp="bibl01">
                    <head type="main"> Are You Unlucky? </head>
                    <head type="sub">Gene will change your luck!</head>
                    <p>Aladdin's Own Lucky Gene cast from the ancient origina. 4K gleaming Gold
                        plate. Famous for good luck. Rub him. He's yours to command. Try
                        him&#8212;See your LUCK improve or your money back. Free history. Free
                        lucky. Book &amp; famous good luk prayer. No C.O.D.'s.
                        <address><addressLine>Advance Merchandise Corporation of America</addressLine>                            <addressLine>Box 617, Dept. MM</addressLine>                            <addressLine>Lynbrook, N.Y. 11563</addressLine></address>
                    </p>
                </ad>
return
local:main()

I am not sure if this is not testable with some of the data, and hopefully this would give you some ideas of why this is not outputting the error message it should be. Have I missed anything else here?

Thanks again.

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