Project

Profile

Help

Should `-s` command line argument to XQuery be ignored when query declares "declare context item := document{<root>...</root>}" without "external"?

Added by Martin Honnen over 5 years ago

When I write a query like

xquery version "3.1";

declare context item := document {
<root>
<foo>bar</foo>
</root>
};

.

and execute it with Saxon Saxon-HE 9.8.0.14J from the command line I get the declared context item output.

However, when I additionally provide a -s:foo.xml command line option, the query returns that file and not the declared context item.

https://www.w3.org/TR/xquery-31/#id-context-item-declarations defines the syntax of the context item declaration as

ContextItemDecl	   ::=   	"declare" "context" "item" ("as" ItemType)? ((":=" VarValue) | ("external" (":=" VarDefaultValue)?))

and says

If VarValue is specified, then the initial context item is the result of evaluating VarValue.

Note:

In such a case, the initial context item does not obtain its value from the external environment. If the external environment attempts to provide a value for the initial context item, it is outside the scope of this specification whether that is ignored, or results in an error.

So I wonder whether Saxon should not either ignore the -s provided value or raise an error. Overriding the declared VarValue in the query seems to be what should only happen in case of using "external", e.g. declare context item external := document{<root>...</root>};.


    (1-1/1)

    Please register to reply