[xquery-talk] if statements within where clauses?
Cindy Girard
clm6u at virginia.edu
Wed Jun 14 15:45:59 PDT 2006
Thanks, Jonathan.
I switched it to this:
$hits :=
for $entries in collection($collctn)//tei.2
let $docname := concat($entries/@id, '.xml')
let $divs := $entries//div1
let $text := $entries/text
where contains($text, $keyword)
and if ($region = 'all') then ()
else $entries//classcode = $region
and if ($gender = 'all') then ()
else $entries//classcode = $gender
and if ($race = 'all') then ()
else $entries//classcode = $race
and if ($type = 'all') then ()
else $entries/@type = $type
return
<doc>{$entries/@type, <ct>-</ct>}</doc>,
But I get the following error:
Error: Error in XQuery expression: syntax error, unexpected "if" [err:XPST0003],
What else can I try?
Thanks,
Cindy
JR> Jonathan Robie wrote:
>> Hi Cindy,
>>
>> XQuery allows expressions to be combined very freely, and you can
>> certainly use an if expression for conditional logic in a WHERE
>> clause, as follows:
>>
>> ....
>> where contains($text, $keyword)
>> and if ($var ='all')
>> $entries//classcode = $region
>> else
>> true()
>>
>> I did not understand what you are trying to do well enough to know
>> exactly what the query should look like.
>>
>> Hope this helps!
>>
>> Jonathan
>>
JR> _______________________________________________
JR> talk at xquery.com
JR> http://xquery.com/mailman/listinfo/talk
--
- Cindy
More information about the talk
mailing list