WebReference.com - Excerpt from Inside XSLT, Chapter 2, Part 4 (4/4)
XML Base Support
One of the additions to the XSLT 1.1 working draft was support for the W3C XML Base specification. As of this writing, the XML Base specification is in Proposed Recommendation form (dated 20 December 2000), and you can find the current version of this document at www.w3.org/TR/xmlbase/. [And as of this posting, the recommendation is dated June 27, 2001 - Ed.]
This specification enables you to provide a base URI for XML and XSL
documents, just like the HTML
<BASE> element. (In fact, the HTML
<BASE> element is the reason XBase exists-W3C is committed to
giving XML all the power HTML 4.0 linking has, and then build on that.) As you recall,
one of the properties of XSL elements is their base URI, and now you can use XML Base
to set that URI. However, no XSLT processors that I know of support XML Base yet.
You can find full coverage of XML Base in Inside XML. Here's how it works
in overview: You can use the
xml:base attribute in an XML document to set the
document's base URI. The other URIs in the document are then resolved using that value
as a base. Note that
xml:base uses the xml namespace; the xml namespace is
predefined in XML as "http://www.w3.org/XML/1998/namespace". The following example uses XML
links (that is, XLinks, as also covered in Inside XML):
<?xml version="1.0"?> <MOVIE_REVIEW xmlns:xlink = "http://www.w3.org/1999/xlink" xml:base="http://www.starpowder.com/" xlink:type = "simple" xlink:show = "new" xlink:href = "reviews.xml"> Mr. Blandings Builds His Dream House </MOVIE_REVIEW>
Using the value assigned to the
xml:base attribute, the URI in this
xlink:href attribute, "reviews.xml", is resolved to the full URI
"http://www.starpowder.com/reviews.xml". In this way, you can use
xml:base to provide
a base URI for a document or a specific element.
In the XSLT 1.1 working draft, every node has an associated URI called its base URI, which is used for resolving attribute values that represent relative URIs into absolute URIs. Here's how you determine the base URI:
- The base URI for a root node is the URI of the document.
- The base URI for an element node is the base URI specified by an
xml:baseattribute in the element (if one exists), or the base URI of the element's parent element in the document or external entity (if one exists), or the base URI of the document entity or external entity that contains the element.
- The base URI for a processing instruction node is the URI that would apply to a URI reference in the content of the processing instruction. According to the XML Base specification, the base URI for a URI reference appearing in the content of a processing instruction is the base URI of the parent element of the processing instruction (if one exists), within the document entity or external entity, or the base URI of the document entity or external entity containing the processing instruction.
- The base URI for a text node, a comment node, or an attribute node is the base URI of the parent of the node.
- The base URI for a namespace node, however, is implementation-dependent.
Setting the base URI of documents and elements can be useful if you have an extensive set of documents to work with. If you reorganize that document set, you need to reset only the base URI as appropriate, not all individual URIs. As I said, however, no XSLT processors that I know of have any support for XML Base yet.
Created: October 4, 2001
Revised: October 4, 2001