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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions proposal-template.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
# Title of Your Syntax Extensions
# Namespace prefix binding expression

**Author**: Your name. Optional: company and optional contact email.
**Author**: Liam Quin, https://www.delightfulcomputing.com/

Short description goes here.
A difficulty with XPath has always been that there is no way to associate a namespace URI with a prefix in pure XPath, so you end up writing stuff like /*[local-name() eq 'html' and namespace-uri(.) = 'http://www.w3.org/1999/xhtml']/*[local-name() eq 'body' and namespace-uri(.) eq 'http://www.w3.org/1999/xhtml']/...

So this is a proposal for
with prefix h := "http://www.w3.org/1999/xhtml" return //html/body

## Description
I seem to remember that for this to work in XQuery as well as XPath it has to have a pair of tokens, hence "with prefix". It would of course take a list,
with prefix p1 := n1, p2 := n2 return singleExpr

Longer description goes here include syntax and technical detail. Also include details of influences (if any) and relevant comparisons, e.g. Haskell does X whilst Scala does Y.
The list should be allowed to be empty, to help automatic generation of XPath or XQuery fragments.

I raised this idea within the Working group meetings, but then the feeling was EQNames would satisfy this. So, you can write,
/"http://www.w3.org/1999/xhtml"html/"http://www.w3.org/1999/xhtml"body
but i don't find this helps make the resulting expression very readable.

## Use Cases
In the examples i've used, the prefix is an NCName - it could be any expression evaluating to an NCName i suppose, although i don't have a use case for that, and there would be no way to use the result in the expression, so a literal NCName seems best to me.

Details of why this is desired and the advantages that it brings. You should also mention any disadvanges it might bring, like code complexity or confusion with any other existing syntax.


## Examples

Examples of valid and invalid use of your syntax extension.


## Grammar

Optional. You could describe your extension in terms of EBNF, and bonus points if you describe how it fits into the existing EBNF of XPath ;-)