The following xquery code runs into the error „Context is undeclared“. I am using BaseX v9.1.2.
How is it possible that this error happens there?
In your return statement, there is no context for the XPath to be applied. Use the $el variable bound in your loop:
$el
return <key-val><key>{ data($el/as:SERVICE-INSTANCE-REFS/...