This entry concerns two problems relating to the use of global variables ("declare variable") in XQuery, where the initializing expression for the variable depends on the context item set externally for the query.
(The XQuery specification doesn't actually say this is allowed, but the question has been raised and an erratum is expected confirming that it is legal.)
Firstly, if the query is called from the command line, and the main query body does not reference the context item, then Saxon reports that the -s option on the command line was ignored. The source document is not loaded, and evaluation of the variable that requires the context item then fails saying no context item was supplied.
Secondly, when using document projection, the paths computed for the query (which determine which parts of the source document are retained when constructing the tree) do not take into account parts of the source document needed to compute global variables.
A patch fixing these problems is being placed in Subversion.