Re: [xsl] XSLT - base URL for relative file paths - from Stylesheet location or XML document location?

Subject: Re: [xsl] XSLT - base URL for relative file paths - from Stylesheet location or XML document location?
From: Mike Brown <mike@xxxxxxxx>
Date: Wed, 14 May 2003 11:14:11 -0600 (MDT)
Mike Trotman wrote:
> I am processing several XML files in different locations linked by an index
> XML file that contains the relative paths to each XML file.
> I am also using stylesheets in several different directories.
> When using different XSLT processors there seems to be at least two
> different conventions being used for WHICH of the stylesheet or the document
> (or maybe even the calling location?) determines the base URL for relative
> files paths.
> Is this specified unambiguously in the W3C standard (I thought it was) or is
> it unspecified / open to different interpretations by different XSLT
> implementers?

The points that are not ambiguous are:

1. Regardless of what the base URI is, as long as it's a URL, there is
no room for interpretation in how it is resolved against a base to absolute
form; this is clearly defined in RFC 2396 and XSLT processors must honor it.

2. In XSLT, each node has a base URI property: it is the URI of the
document/entity from which the node originated. The base URI of the xsl:import
or xsl:include element node, or the element node with the attribute that
contains the document() call, is the URI used for resolving relative URI
references in the href or in the first argument to document(). Unfortunately,
in XSLT 1.0, you don't have access to the base URI; you're supposed to be able
to get by without it.

You are probably running into the complication that there is no standard
procedure for XSLT processors to use when deducing URIs that are not
explicitly provided. If you don't label the processor's input with absolute
(scheme-having) URIs, then the processor is going to use its own most-likely
imperfect logic to fabricate the URIs for you.

For example, if you pass an OS-specific relative path to the source XML on the
command line, and in the stylesheet you refer to the same document via a
document() call with an explicit, absolute URI, are they treated as the same
document? (they should be). That is, does generate-id(/) return the same
string as generate-id(document('file:///path/to/source.xml'))?

6 months ago I made a stylesheet that helps test how well processors behave in
this regard [1]. The results were very inconsistent.

Before deciding that you've found a bug, experiment with ways of supplying the
URIs for the input (source XML and stylesheet). For example, in JAXP,
InputSource objects have a setSystemId method, I believe. You should use it
even if the source is a stream; set it to something that should result in the
desired resolution of relative references in the document. Also be sure you're
not confusing OS-specific paths with URIs; in your XSLT and XML you should only
be using URIs. e.g., 'C:\path\to\file' should be 'file:///C:/path/to/file'
(perhaps use | instead of :, too)



 XSL-List info and archive:

Current Thread
  • RE: [xsl] XML merge
    • Jarno . Elovirta - Wed, 14 May 2003 12:16:04 +0300
      • <Possible follow-ups>
      • Molnar Agnes - Wed, 14 May 2003 18:43:21 +0200 (CEST)
        • Mike Trotman - Wed, 14 May 2003 16:52:18 +0100
          • Mike Brown - Wed, 14 May 2003 11:14:11 -0600 (MDT) <=
          • Michael Kay - Wed, 14 May 2003 19:10:47 +0100
          • TP - Wed, 14 May 2003 13:24:39 -0500
          • TP - Thu, 15 May 2003 07:57:38 -0500