Re: XSLT - base URL for relative file paths - from Sty
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 . 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)  http://skew.org/xml/stylesheets/doc-id/ -Mike XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
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