How to create an if statement without else in XQuery?

I want to create an instruction ifwithout a part elsein XQuery.

For example:

<results>
   { 
   if (5 = 5) then
       <foo/>
   }
<results>

How to do it?

I also tried this:

<results>
   { 
   if (5 = 5) then
       <foo/>
   else
       return
   }
<results>

which, although compiled, does not work at work!

+4
source share
2 answers

There are no ifoperators without XQuery else. Return an empty sequence instead of ()or any reasonable identification element (usually this is what you need if nothing specific is defined).

if ($foo eq "bar")
then
  42
else
  ()

, "no else" " ", XQuery , , "-". ""? , , "no else , ", W3C XML Query, , , . , , , , , , "else"; : 0 - , 1, , "" , , ,...

"empty return statements"

"" , <return/> , else return - else ./return. ( -), <return/> , .

, , . , .

+7

:

<results>
   { 
       <foo/> [5 = 5]
   }
</results>
0

Source: https://habr.com/ru/post/1618292/


All Articles