RE: Behavior of document() Function with Empty String
> The document() function is a source of never-ending confusion > for me. As I understand it, the document() function should > return the root node of the "current" stylesheet (the one > which invoked the function). document('') resolves the relative URI '' against the base URI of the element in the stylesheet that contains the XPath expression in which the call to document('') appears. Provided that the stylesheet module is loaded from a location whose URI is known, that you don't use xml:base, and that you don't use XML external entities, XInclude, or other such means of constructing stylesheets, this will normally refer to the stylesheet module containing the call on document(''). It's true that RFC 2396 defines special treatment for the relative URI "". See G.4: RFC 1808 (Section 4) defined an empty URL reference (a reference containing nothing aside from the fragment identifier) as being a reference to the base URL. Unfortunately, that definition could be interpreted, upon selection of such a reference, as a new retrieval action on that resource. Since the normal intent of such references is for the user agent to change its view of the current document to the beginning of the specified fragment within that document, not to make an additional request of the resource, a description of how to correctly interpret an empty reference has been added in Section 4. This material is rewritten in RFC 3986 to make it less browser-oriented. The vaguely-defined concept of "current document" has been removed; instead certain relative URIs (including "") are classified as "same-document references" (section 4.4). The URI is resolved against the base URI in the normal way, and is considered a same-document reference if the result is identical to the base URI excepting any fragment identifier; section 4.4 then contains the rule that when a same-document URI is dereferenced, the dereference should not result in a new retrieval action. I don't think there has been any discussion of whether this change in the RFCs affects the treatment of document("") in XSLT. In Saxon, certainly, document("") *does* result in a new retrieval action, because the document representing the stylesheet module is not otherwise available at run-time. Michael Kay http://www.saxonica.com/
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format