Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal - namespace binding in XPath #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

liamquin
Copy link

@liamquin liamquin commented Sep 3, 2020

No description provided.

Copy link
Member

@michaelhkay michaelhkay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I certainly think it would be useful to be able to supply the namespace context as part of the expression. Are you proposing that this can appear anywhere an expression appears, or only at the top level? Can it be used to set the default namespace [for elements and types]? Might it be better to use the XQuery syntax (declare namespace) - I prefer your syntax, but compatibility is a thing...

@liamquin
Copy link
Author

liamquin commented Sep 3, 2020 via email

@adamretter
Copy link
Member

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...

@ChristianGruen
Copy link
Member

ChristianGruen commented Sep 6, 2020

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?

@michaelhkay
Copy link
Member

michaelhkay commented Sep 6, 2020

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 an NCName is present, then:

** 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

  • If the NCName is absent, then the default element/type namespace is set to the value of the URILiteral, or to absent if the URILiteral is the zero-length string.

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.

@liamquin
Copy link
Author

liamquin commented Sep 6, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants