[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Proposed syntax for namespace binding in XPath

Subject: Proposed syntax for namespace binding in XPath
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 31 Mar 2007 23:58:06 +0100
 Proposed syntax for namespace binding in XPath
I'd like to solicit reactions to a proposal to define an informal standard
for binding namespaces in strings containing XPath expressions.

I see a lot of people using XPath from Java and also using saxon:evaluate to
evaluate dynamically-constructed XPath expressions from XSLT or XQuery. One
of the difficulties with such interfaces has always been that defining the
namespace bindings is messy - in fact, in saxon:evaluate, it can't be done
dynamically at all.

Clearly a vendor-defined API can take as input some string that contains a
set of namespace bindings followed by an XPath expression. This doesn't
violate XPath conformance; it just means that the string passed to the API
contains an XPath expression embedded in something else. Hopefully other
systems that offer XPath APIs will follow suit, and we can establish an
informal standard rather along the lines of the Clark notation for expanded
QNames "{uri}local".

In choosing a syntax I'd like something that falls back to standard XPath if
there are no namespace bindings, and where it's very easy to spot that
namespace bindings are present if this is the case. I think that in the
XPath house-style, it should also be less wordy than the XQuery prolog which
uses

declare default element namespace x = "uri";

I would also like something that can be written in an XML attribute, so
characters such as "<" (and ideally quotes) should be avoided.

XPointer has a mechanism that's one possible candidate: the xmlns() scheme:

http://www.w3.org/TR/xptr-xmlns/

An example is

xmlns(abc=http://example.com/ns/abc)

or in context,

xmlns(c=http://example.org/customer)
xmlns(p=http://example.org/personal-info)
xpointer(/c:customer/p:name)

There are several disadvantages to adopting this directly. It doesn't allow
the default namespace to be bound; it's not easily distinguishable from a
function call; it can't handle a URI containing an unpaired right bracket;
and it doesn't fall back to pure XPath when there are no bindings.

The syntax I'm thinking of using is:

(:# xmlns=http://default/uri xmlns:p=http://other/uri #:) xpath-expression

Using a special comment has the advantage that XPath processors that don't
understand the notation will ignore it (though I freely admit that
"meaningful comments" have their drawbacks). It avoids use of quotes which
makes it easy to embed in an XML attribute, and it uses space to delimit the
URI - although there is no absolute ban on having a space in a namespace
URI, there are already plenty of things that will break if you do it, so
it's unlikely to cause any new problems.

Michael Kay
http://www.saxonica.com/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.