tags:

views:

31

answers:

3

Is there a way to set the base URI in XSLT so it applies for the whole document like in XQuery?

I.e.

declare base-uri = "someuri";
A: 

I think what you want is the xml:base attribute on the document root node.

See http://www.w3.org/TR/xmlbase/ to confirm this will do what you want.

Jim Garrison
A: 

It is not possible to change the base URI of a document. From the XML Base W3C Spec.:

"The base URI of a document entity or an external entity is determined by RFC 3986 rules, namely, that the base URI is the URI used to retrieve the document entity or external entity."

The base URI of any node in the document (with the exception of the document-node()) can be set using xml:base (again there)

"The attribute xml:base may be inserted in XML documents to specify a base URI other than the base URI of the document or external entity"

Dimitre Novatchev
A: 

From http://www.w3.org/TR/xslt#document

The URI reference may be relative. The base URI (see [3.2 Base URI]) of the node in the second argument node-set that is first in document order is used as the base URI for resolving the relative URI into an absolute URI. If the second argument is omitted, then it defaults to the node in the stylesheet that contains the expression that includes the call to the document function.

And from http://www.w3.org/TR/xslt#base-uri

Every node also has an associated URI called its base URI, which is used for resolving attribute values that represent relative URIs into absolute URIs. If an element or processing instruction occurs in an external entity, the base URI of that element or processing instruction is the URI of the external entity; otherwise, the base URI is the base URI of the document. The base URI of the document node is the URI of the document entity. The base URI for a text node, a comment node, an attribute node or a namespace node is the base URI of the parent of the node.

So this:

<xsl:copy-of select="document('external.xml')" xml:base="http://example.org"&gt;

Should be resolved as

<xsl:copy-of select="document('http://example.org/external.xml')"&gt;
Alejandro