Grauw’s blog

Base URIs, too

August 15th, 2005

In response to a post on Anne’s blog, here are my thoughts on base URIs (xml:base in particular), which are still only seldom used...

I’d say this a nice example of putting xml:base to good use:

<style type="text/css" xml:base="css/">
h1 { background: url(images/bg.png); }

URIs 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 it is quite useful, too, 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, 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. 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 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.



Compound documents by Grauw at 2005-08-16 10:06

A nice reply by Sjoerd Visscher on Anne’s weblog, which I think is valuable to post here as well:

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!

Nice sharing..... by ccna notes at 2010-02-22 08:07

well jouli here.i raed your comment and totally agree with you.its nice sharing with here finding .but its Very great theme ! i really enjoy it, thanks a lot for sharing the different step of creation, very interesting to know !