Hi Ruth,
A for loop iterates over each result of the in expression individually. So
$qresults always contains exactly one result, if there is any. If there are no
results, the return is never reached.
It will work better when you write it like this:
let $q := xdmp:get-request-field("wcq")
let $qresults := cts:search(doc("wcresults.xml")/wc:wcresults/wc:wcresult,
$q)
return
if ($qresults) then
for $qresult in $qresults
return
<p>{fn:string($qresult)}</p>
else
<b>No matches found.</b>
Kind regards,
Geert
>
Drs. G.P.H. Josten
Consultant
http://www.daidalos.nl/
Daidalos BV
Source of Innovation
Hoekeindsehof 1-4
2665 JZ Bleiswijk
Tel.: +31 (0) 10 850 1200
Fax: +31 (0) 10 850 1199
http://www.daidalos.nl/
KvK 27164984
De informatie - verzonden in of met dit emailbericht - is afkomstig van
Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit
bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit
bericht kunnen geen rechten worden ontleend.
> From: [email protected]
> [mailto:[email protected]] On Behalf Of
> Ruth Stryker
> Sent: dinsdag 1 december 2009 7:56
> To: General Mark Logic Developer Discussion
> Subject: [MarkLogic Dev General] newbie cts:search
>
> Hi,
>
> I've created a simple self-submitting query form that works
> except for one small part: 'No matches found.' never appears
> (even when there are no matches). I'm guessing $qresults is
> always true and that I am either not using cts:search
> correctly or that I am not approaching this situation
> correctly (have had to self-teach myself XQuery/ML over the
> past couple days). Any help would be greatly appreciated (and
> I would of course be happy to further explain if this isn't
> enough information).
>
> Thanks,
> Ruth
>
>
> declare function local:showresults()
> {
> if(xdmp:get-request-field("wcq")) then
>
> let $q := xdmp:get-request-field("wcq")
> for $qresults in
> cts:search(doc("wcresults.xml")/wc:wcresults/wc:wcresult,
> $q)
> return
> if($qresults) then <p>{fn:string($qresults)}</p>
> else <b>No matches found.</b>
>
> else ()
> };
>
> _______________________________________________
> General mailing list
> [email protected]
> http://xqzone.com/mailman/listinfo/general
>
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general