Open liamquin opened 4 years ago
This seems like a sensible addition to me. I was thinking to myself "this could be nicely expressed as a Pragma", then I realised of course that Pragma is only in XQuery.
Let's leave this open for a couple of days for any more comments, and then all being well, let's merge it...
Do we also want to provide support for declaring the default element namespace (something like with prefix := ...
or with prefix '' := ...
)?
And I guess that new prefixes will shadow existing ones?
So let's try and flesh out the proposal.
We have a new kind of PrimaryExpr:
[56] PrimaryExpr ::= .... | WithPrefixExpr [56a] WithPrefixExpr ::= "with" "prefix" NCName? "=" URILiteral ("," "prefix" NCName? "=" URILiteral)* ) EnclosedExpr
Semantics: The result of a WithPrefixExpr is the result of the EnclosedExpr, evaluated with a static context that varies the set of namespace bindings.
Specifically, for each "prefix" clause, the static context for EnclosedExpr (the "inner context) is based on the static context of the WithPrefixExp (the "outer context") altered as follows:
** if the URILiteral is a zero-length string, any binding of the NCName to a URI in the outer context will be absent from the inner context (if there is no such binding in the outer context, then the declaration has no effect)
** Otherwise, the set of statically known namespaces in the inner context contains a (prefix, URI) binding for this NCName and the corresponding URILiteral, replacing any binding for this NCName that exists in the outer context
Error conditions:
The same NCName must not appear more than once.
There must not be more than one "prefix" clause with an absent NCName.
Note:
the syntax is designed with extensibility in mind, so that we could add other clauses that vary the static context, for example "with default-collation = URILiteral {...}"
I've used "=" rather than ":=" for consistency with "declare namespace" in XQuery.
On Sun, 2020-09-06 at 04:37 -0700, Michael Kay wrote:
So let's try and flesh out the proposal.
Hah! I saw Adam's comment and was about to sit down & try and make a more formal propoosal, and it had already happened! Thank you for doing that.
I think the changes - default, and using = instead of :- = are fine (i used := by analogy with let but since both are in use this is fine too).
We have a new kind of PrimaryExpr:
[56] PrimaryExpr ::= .... | WithPrefixExpr [56a] WithPrefixExpr ::= "with" "prefix" NCName? "=" URILiteral ("," "prefix" NCName? ":=" URILiteral)* ) EnclosedExpr
Does this work without ambiguity in XQuery as well as XPath?
If it wasn't so long and wordy, with namespace = "http:/example.og/" /a/b[ c= 7]/d is clearer than with prefix, and still works for with namespace xs = "https://www.w3.org/2001/xsd/" xs:integer but i'm happy either way, thanks again for looking at this.
-- Liam Quin, https://www.delightfulcomputing.com/ Available for XML/Document/Information Architecture/XSLT/ XSL/XQuery/Web/Text Processing/A11Y training, work & consulting. Barefoot Web-slave, antique illustrations: http://www.fromoldbooks.org
On Thu, 2020-09-03 at 00:43 -0700, Michael Kay wrote:
Not as written but that would be a good addition, thank you!
Because it can appear in the body of an expression, it's doing something different, and we don't currently have semicolon-terminated declarations in XPath.
I was thinking that this does no more than introduce a prefix - it does not for example directly affect the in-scope namespaces any differently than using an EQName in an expression.
-- Liam Quin, https://www.delightfulcomputing.com/ Available for XML/Document/Information Architecture/XSLT/ XSL/XQuery/Web/Text Processing/A11Y training, work & consulting. Barefoot Web-slave, antique illustrations: http://www.fromoldbooks.org