[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

If Statements within an If Statement?

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


  If Statements within an If Statement?
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: http://x-query.com/mailman/listinfo/talk 
> [mailto:http://x-query.com/mailman/listinfo/talk] On Behalf Of Wei, Alice J.
> Sent: 02 April 2008 21:20
> To: http://x-query.com/mailman/listinfo/talk
> Subject:  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 http://x-query.com/mailman/listinfo/talk
> 
> _______________________________________________
> http://x-query.com/mailman/listinfo/talk
> http://x-query.com/mailman/listinfo/talk



Purchase Stylus Studio Online Today!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.