[xquery-talk] nested if, then, for statements
Jeni Tennison
jeni at jenitennison.com
Thu Nov 11 21:03:57 PST 2004
Hi Cindy,
> I'm trying to do something like the statement below, but I'm getting
> errors. Do I have the syntax wrong, or do I need to go about it
> completely differently?
You have (quite a lot of) the syntax wrong. The syntax of if is:
if (condition) then result1 else result2
The brackets around the condition are required. There will usually be
brackets around result1 and result2 as well.
The syntax of for is (basically):
for $variable in sequence return result
There must not be anything but whitespace between the "for" and the
"$" of the variable definition. There will usually be brackets around
the result.
There's no such operator as "&=" in XQuery. I think you need the
contains() function instead, although you might want matches().
So I think your query should look like:
let $query :=
if ($ttl != "") then (
for $entries in collection($collctn)//TEI.2
[contains(., $kwds) and
descendant::head[contains(., $ttl)]
return (
if ($entries/@id = "ppp.00271") then (
...
)
else if ($entries/@id = "ppp.00237") then (
...
)
else if ($entries/@id = "ppp.00473") then (
...
)
else (
...
)
)
else if (...) then (
...
)
else (
...
)
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
More information about the talk
mailing list