Bug #4329


Getting warning "Source document ignored - query does not access the context item" although XQuery accesses /*/* (in right hand side of let expression)

Added by Martin Honnen almost 3 years ago. Updated over 2 years ago.

XQuery conformance
Start date:
Due date:
% Done:


Estimated time:
Legacy ID:
Applies to branch:
9.9, trunk
Fix Committed on Branch:
9.9, trunk
Fixed in Maintenance Release:


Trying to write an XQuery based splitting of a large input into several ones using tumbling window I have run into two problems with Saxon 9 (tested with Saxon-HE, this bug is about the first issue:

Although the query accesses the source document with /*/* Saxon emits a warning claiming

Source document ignored - query does not access the context item

Full command line output is:

PS C:\SomeDir> java -cp 'C:\Program Files\Saxonica\
Saxon9.9HE\saxon9he.jar' net.sf.saxon.Query -t -s:.\input-sample-2000-records.xml .\test-xquery-split-result-1.xq
Saxon-HE from Saxonica
Java version 1.8.0_221
Analyzing query from .\test-xquery-split-result-1.xq
Analysis time: 243.5237 milliseconds
Processing file:/C:/SomeDir/./input-sample-2000-rec
Source document ignored - query does not access the context item
<?xml version="1.0" encoding="UTF-8"?>trueExecution time: 12.4667ms
Memory used: 36,983,024

Sample query is:

declare namespace output = "";

declare option output:method 'xml';
declare option output:indent 'yes';

declare variable $chunk-size as xs:integer external := 500;

let $results := 
    for tumbling window $chunk in /*/*
    start at $sp when $sp mod $chunk-size = 1
        document {
            element { node-name(head($chunk)/..) } {
return $results instance of document-node()*

I have attached the input sample.

I think the warning is wrong and indicates that Saxon somehow rewrites the query in the wrong way.

A variation of the query generates a java.lang.NullPointerException, I will fail that as a separate issue as I am not sure it is the same problem or a different code path.


input-sample-2000-records.xml (182 KB) input-sample-2000-records.xml Martin Honnen, 2019-10-02 14:08
Actions #1

Updated by Michael Kay almost 3 years ago

I think Saxon is working out at compile time that $results can only be a sequence of zero or more document nodes, and that the result is therefore always true, regardless of the input. I agree the warning is a bit unhelpful in this case.

Actions #2

Updated by Michael Kay almost 3 years ago

  • Status changed from New to Resolved
  • Applies to branch trunk added
  • Fix Committed on Branch 9.9, trunk added

I'm fixing this by changing the message to the slightly more precise:

Source document ignored - query can be evaluated without reference to the context item

Actions #3

Updated by O'Neil Delpratt over 2 years ago

  • Status changed from Resolved to Closed
  • Fixed in Maintenance Release added

Patch committed to the Saxon maintenance release.

Please register to edit this issue

Also available in: Atom PDF