Sjoerd Visscher probably knows the most on this subject. Or perhaps he is just the only person to care. Anyway, he just wrote how to use base URIs, which basically tells authors not to use them in the way they are considered to be useful. This advice comes from one of the editors of internet standard 66 which is about URIs and is more commonly referred to as RFC 3986. His statement is not specified anywhere though, just on non normative mailing lists around the globe. For what it's worth:
An Internet Standard is a specification that is stable and well-understood.
As I have too little time to really go into the issue I hope this post will be comment driven. And if not, it contains some useful pointers.
Previous thoughts on base URIs and especially same-document references — which is a term that is quite important in this discussion — can be found here. (As I said, Sjoerd his topic.)
I have posted this to the Atom mailing list. Tim Bray is going to change his feed. But Sam Ruby isn't convinced yet.
And yes, I do care a lot. URIs are the building blocks of the web. And the base URI / relative URI is very well thought out, only badly understood IMHO.
I'm wondering how many people had any clue that using base URIs to make URIs shorter is considered an abuse. I didn't before I read Roys post.
Does that mean that the meaning of the base URI in a document always points to the source of the data? That is, if I take data from http://example.com/foo:
<div>
<p href="#ent">to foo link</p>
<p id="ent">foo to you!</p>
</div>
Then take data from http://example.com/bar:
<div>
<p href="#ent">to bar link</p>
<p id="ent">bar none!</p>
</div>
Then put them into document at http://example.com/foobar:
<div xml:base="http://example.com/foo">
<p href="#ent">to foo link</p>
<p id="ent">foo to you!</p>
</div>
<div xml:base="http://example.com/bar">
<p href="#ent">to bar link</p>
<p id="ent">bar none!</p>
</div>
Then both are same-document links, but different same-document links. Could xml:base be used then as a sort-of blockquote@cite attribute for data taken from other contexts?
P.S. Your software chokes on CDATA sections! Ick!
P.P.S. Happy belated birthday.
Maybe you’ll consider this a nice example of base URI:
<style xml:base="css/"> h1 { background: url(images/bg.png); } </style>
URLs in CSS are relative to the file that contains it, and that means that inline CSS is relative to the document instead of e.g. to a common /css/ directory.
For single-page interfaces (pardon the plug ;p) it is quite useful, because the files that are loaded into the document have the same base URI as the document root, while you might for example want them to resolve the paths of images etc. relative to the document and not to the root. To solve that, you could place a base URI on the root element of the loaded segment.
This is valid for XHTML 2.0, too - usually, if you have e.g. a menu, its paths are relative to the root: you prefix them with a / so that the menu still works even though the actual document is at e.g. http://www.grauw.nl/blog/. This has the limitation however that the base of your site has to be in the root of your URL - I can’t just relocate my website to http://www.grauw.nl/site/. If you instead just specify an xml:base
on the menu, and use relative links, then such a thing is only a matter of changing the base URI.
With regard to XPath, in XPath 2.0 there is the function fn:resolve-uri()
. With only one parameter (a relative URI), it will be resolved to the static context. I think this includes changes of the context caused by xml:base
, if supported by the XSLT processor. And even if this is not the case, it isn’t really hard to write a custom function which resolves an URI by recursively resolving xml:base
attributes up the document tree.
Owh, I meant just XHTML, not XHTML 2.0 in particular.
And congratulations on being a W3C member! Sounds wonderful :).
~Grauw
Jimmy: you can't have 2 equal IDs in one document, but otherwise you are spot on. The base URI is a lot like @cite.
Laurens: Yes, actually base URIs are only relevant with compound documents (So Anne, pay attention!) like Single Page Interfaces (pardon the plug, bottom of the page, note the date, pardon again). And a menu that is inserted on every page of the site fits the description of a compound document rather well, and as such, xml:base solves the problems of a menu just as well. And if you use XInclude, the xml:base will be set for you automatically!
Is this also about the HTML BASE
element? Because then I'm confused...
Ben: yes. Surprising isn't it?
Hmm, how many base
s are there again?
*Looking around …*
*Sneak into …*
All your base
are belong to us!
GDRVVF
SCNR