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

Michael Kay mike at saxonica.com
Wed Apr 2 22:43:16 PST 2008


As far as I can see your syntax is OK and your if expression should always
return something. If it doesn't return anything, then perhaps it isn't being
executed, which could be because your FLOWR expression is selecting no
tuples.

Of course, you haven't provided enough information for me to test it, and
the fact that I can't see an error when scanning it by eye doesn't mean that
there is no error.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: talk-bounces at x-query.com 
> [mailto:talk-bounces at x-query.com] On Behalf Of Wei, Alice J.
> Sent: 02 April 2008 21:20
> To: talk at x-query.com
> Subject: [xquery-talk] If Statements within an If Statement?
> 
> 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
> return
> <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> }; local:searchresult($a union $d
> 
> I would like to have this so that it can say something like
> 
> return
> 
> 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> 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>
> 
> 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
> ======================================================
> Alice Wei
> MIS 2008
> School of Library and Information Science Indiana University 
> Bloomington ajwei at indiana.edu
> 
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk



More information about the talk mailing list