xqueryzorba

Syntax error with quantified expressions in XQuery, using 'some in satisfies'


I am trying to figure out what is wrong with the following query:

for $item in doc("rss.xml")//item
let $title := lower-case($item/title)
let $description := lower-case($item/description)
where contains($title, "keyword") or
  contains($description, "keyword") or
  some $category in $item/category 
    satisfies contains($category, lower-case("keyword"))
return <tr>
  <td>{data($item/title)}</td>
  <td>{data($item/pubDate)}</td>
  </tr>

I started to get a syntax error after adding the some satisfies condition:

some $category in $item/category 
        satisfies contains($category, lower-case("keyword"))

The syntax error I am getting is:

static error [err:XPST0003]: invalid expression: syntax error, unexpected "$"

I am using Zorba to process the query, the rss.xml file contains an RSS feed. Like I said, the query works fine with just the two contains tests.


Solution

  • An extra pair of parentheses is necessary around the QuantifiedExpr for embedding it into the OrExpr:

                                    ... or
      (some $category in $item/category 
        satisfies contains($category, lower-case("keyword")))
    return ...
    

    QuantifiedExpr has a lower precedence than an OrExpr. Look up OrExpr in an XQuery grammar and find that it requires a ParenthesizedExpr for adding a QuantifiedExpr.

    Without the parentheses, some syntactically is a QName and $ is not a valid continuation after that. So Zorba is right to complain, and any other XQuery parser would likely do the same.