XQuery if sencence

Hello!!
I am quite new with XQuery and i’ve a problem with if-sentence.

I want to replace a node if the condition is true, else insert a node. The problem is the following one. I need to prove that two attributes of the same node!!! and I don’t know how do it!!

This is my Query:

1)update
2) if (document(“D:/AGENCIA.xml”)//AGENCIA/VUELO[@CODIGO=“ZARMAD1”]/PLAZA[@NUMERO=“01”])
3) then
4) replace document(“D://AGENCIA.xml”)//AGENCIA/VUELO[@CODIGO=“ZARMAD1”]/PLAZA[@NUMERO=“01”]
5) with
6) Mr Smith
7)
8) else
9) insert
10) MR Smith
11) 70
12) Bussines
13)
14) into document(“D:/AGENCIA.xml”)//AGENCIA/VUELO[@CODIGO=“ZARMAD1”]/PLAZA;
15)document(“D:/AGENCIA.xml”)

In line 2 is my problem:
PLAZA has two attributes NUMERO adn LIBRE, and I want to do something like :
if(CODIGO=“code” and LIBRE=“TRUE”) but in Xquery of course, could some of you help me, please?

Thanks a lot

Mar

Hello,
you can simulate an if by 2 where expressions
according the approach described below.

Best regards
Walter



if (booleanExpression)
then (expression1)
else (expression2)

is equivalent to Tamino XQuery

let $condition := (booleanExpression)
return (
let $d := “then”
where $condition
return (expression1),
let $d := “else”
where not($condition)
return (expression2),
)

If the conditional expression is not contained in filter or sort expression (it is independent of the context item) then a simpler expression can be used:

let $condition := (booleanExpression)
return ( (expression1)[$condition], (expression2) [not($condition)] )



Example
? W3C XQuery
if (input()/cruise[price = 1088])
then ( )
else ( )

? Tamino XQuery 4
let $condition := (input()/cruise[price = 1088])
return
(let $d := “then”
where $condition
return ,
let $d := “else”
where not($condition)
return )


more simpler case
? W3C XQuery
if (count($b/author) > 2)
then
else ()

? Tamino XQuery 4
let $a:= “then”
where (count($b/author) > 2)
return