2
votes

I am trying this code on MarkLogic console and getting this error

Unexpected token syntax error, unexpected If_

Here is the code

let $name1 := "Bob"
let $name2 := "John"

if(fn:contains($name1, "Bo")) then
 return "Bob is good"
else 
 return "John is good"
1
The let statements begin a FLWOR (let is the L in a FLWOR). The conditional if/else block needs to be part of one of those components. Move the return outside of the if/else to create a fLwoR. en.wikipedia.org/wiki/FLWOR - Mads Hansen
Probably worth adding the above comment to the answer.. - grtjn

1 Answers

5
votes

Your syntax is wrong. Try this-

let $name1 := "Bob"
let $name2 := "John"

return 
  if (fn:contains($name1, "Bo")) then
    "Bob is good"
  else 
    "John is good"