My first attempt to run this was under 9.7 from the command line using -update:discard.
This produced warnings that the predicate [@nr eq 3] would fail unless @nr was empty. The predicate is relying on a schema-aware comparison. So I ran again with the -sa option.
This ran to completion producing blank output.
I then ran with -update:on (having saved a copy of the source document). This crashed with an NPE:
Building tree for null using class net.sf.saxon.tree.linked.LinkedTreeBuilder
java.lang.NullPointerException
at net.sf.saxon.tree.linked.LinkedTreeBuilder.endElement(LinkedTreeBuilder.java:298)
at net.sf.saxon.functions.AnalyzeStringFn.call(AnalyzeStringFn.java:146)
at net.sf.saxon.functions.AnalyzeStringFn.call(AnalyzeStringFn.java:33)
at net.sf.saxon.expr.FunctionCall.iterate(FunctionCall.java:546)
Then I switched to Saxon 9.6 using the command line options
-q:test.xquery -update:discard -t
This gave a warning saying bytecode could not be generated, and then failed with a different NPE:
java.lang.NullPointerException
at net.sf.saxon.expr.instruct.ProcessRegexMatchInstruction.processLeavingTail(ProcessRegexMatchInstruction.java:46)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:144)
at net.sf.saxon.expr.parser.ExpressionTool.evaluate(ExpressionTool.java:325)
at net.sf.saxon.expr.LetExpression.eval(LetExpression.java:476)
at net.sf.saxon.expr.LetExpression.evaluatePendingUpdates(LetExpression.java:711)
at com.saxonica.ee.optim.XQueryExpressionEE.runUpdate(XQueryExpressionEE.java:212)
The error remains if bytecode generation is switched off, and the -sa option also has no effect.
I'm going to start by exploring the 9.7 problem, and then I'll come back to 9.6 later.