- test files: http://www.dbis.informatik.uni-goettingen.de/Mondial/mondial.xml https://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml - call saxon with hamlet.xml as context document for $x in //PERSONA where some $l in /PLAY//LINE satisfies contains($l,$x) return $x (all person names in the "Hamlet" play that are mentioned in some line of it) => 1 result: Guildenstern -- shows that paths accessing the context document are allowed in the where-clause. For the following, again called with hamlet.xml as context document, saxon (9.8.0.7 downloaded 19.1.2018, both HE and EE) throws an error: All country names in "Mondial" that are mentioned in some line of "Hamlet": for $x in doc("file:mondial.xml")//country/name where some $l in /PLAY//LINE satisfies contains($l,$x) return $x ==> may@login:~/teaching/ssd/XQuery$ saxonXQ -s:hamlet.xml hamletmondialbug.xq Exception in thread "main" java.lang.StackOverflowError at net.sf.saxon.expr.Expression.computeDependencies(Expression.java:1231) at net.sf.saxon.expr.Expression.computeStaticProperties(Expression.java:1174) at net.sf.saxon.expr.Expression.getDependencies(Expression.java:765) at net.sf.saxon.expr.Expression.computeDependencies(Expression.java:1234) at net.sf.saxon.expr.Expression.computeStaticProperties(Expression.java:1174) at net.sf.saxon.expr.Expression.getDependencies(Expression.java:765) at net.sf.saxon.expr.Expression.computeDependencies(Expression.java:1234) at net.sf.saxon.expr.Assignation.computeDependencies(Assignation.java:133) at net.sf.saxon.expr.Expression.computeStaticProperties(Expression.java:1174) at net.sf.saxon.expr.Expression.getDependencies(Expression.java:765) at net.sf.saxon.expr.Expression.computeDependencies(Expression.java:1234) at net.sf.saxon.expr.Expression.computeStaticProperties(Expression.java:1174) at net.sf.saxon.expr.Expression.getDependencies(Expression.java:765) at net.sf.saxon.expr.Assignation.countReferences(Assignation.java:502) at net.sf.saxon.expr.Assignation.rebuildReferenceList(Assignation.java:488) at net.sf.saxon.expr.Assignation.verifyReferences(Assignation.java:475) at net.sf.saxon.expr.LetExpression.optimize(LetExpression.java:266) at net.sf.saxon.expr.flwor.FLWORExpression.optimize(FLWORExpression.java:572) at net.sf.saxon.expr.LetExpression.optimize(LetExpression.java:317) [... recursion...] (aside: with saxon9he 9.7.0.8 (from Sept 2016) this worked correctly) Note that let $h := . for $x in doc("file:/home/may/Mondial/Mondial-III/mondial.xml")//country/name where some $l in $h/PLAY//LINE satisfies contains($l,$x) return $x works well and returns 5 results. 20.1.2018 in the morning: solved.