[xsl] Saxon and XT both exhibit unexpected document() behaviour

Subject: [xsl] Saxon and XT both exhibit unexpected document() behaviour
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 03 Dec 2003 21:47:16 -0500
Please bear with me while I describe the situation in which I find myself. After hours of debugging a largish stylesheet with 6 imported fragments and trying to reproduce the problem, I have finally narrowed it down to the shortest reproducable example I could think of with only a single imported fragment.

I delivered a stylesheet to a customer where the document function utilized a URI relative to the stylesheet, and we witnessed what I believe is the incorrect file being accessed when we changed the relative URI from being in the local directory to being in a remote directory.

Below, I have set up data files relative to the stylesheet to be accessed by the stylesheet so I am using a string argument for a relative URI and no second argument, thus the document() function should be relative to the Base URI of the stylesheet fragment that calls document().

In the transcript below you will find:

  (1) - a directory listing showing only four files in two directories:

(2) - the exposition of each data.xml: they identify themselves

(3) - stylesheet dir1/ss1.xsl is run from dir1 and imports dir2/ss2.xsl

(4) - ss2's call to document('data.xml') correctly finds dir2/data.xml

  (5) - ss2's call to document('../data.xml') incorrectly finds dir1/data.xml
        instead of reporting that data.xml is not in the parent directory

Can anyone justify from the XSLT specification why both XT and Instant Saxon 6.5.3 find the dir1/data.xml file when the relative URI is "../data.xml" and the stylesheet fragment is dir2/ss2.xsl? I believe both should be reporting the error that the parent directory of dir2 does not contain the file "data.xml", but if they both are doing the same behaviour then it must be something I'm missing from the spec.

BTW, I did get the expected error when the same document() calls were made in ss1.xsl and no imported fragments. It only happens when being called from an imported fragment, and I use imported fragments for large stylesheets.

Thanks for any help anyone can provide!

...................... Ken

T:\test\dir1>dir \test /s
 Volume in drive T is Crane Data
 Volume Serial Number is 0445-7502

Directory of T:\test

2003-12-03  21:11    <DIR>          .
2003-12-03  21:11    <DIR>          ..
2003-12-03  21:13    <DIR>          dir1
2003-12-03  21:13    <DIR>          dir2
               0 File(s)              0 bytes

Directory of T:\test\dir1

2003-12-03  21:13    <DIR>          .
2003-12-03  21:13    <DIR>          ..
2003-12-03  21:12                24 data.xml
2003-12-03  21:10               296 ss1.xsl
               2 File(s)            320 bytes

Directory of T:\test\dir2

2003-12-03  21:13    <DIR>          .
2003-12-03  21:13    <DIR>          ..
2003-12-03  21:12                24 data.xml
2003-12-03  21:08               340 ss2.xsl
               2 File(s)            364 bytes

     Total Files Listed:
               4 File(s)            684 bytes
               8 Dir(s)  12,797,771,776 bytes free

T:\test\dir1>type data.xml
T:\test\dir1>type ..\dir2\data.xml
T:\test\dir1>type ss1.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";

<xsl:import href="..\dir2\ss2.xsl"/>

<xsl:output method="text"/>

<xsl:template match="/">
  <xsl:call-template name="remote"/>


T:\test\dir1>type ..\dir2\ss2.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";

<xsl:template name="remote">
  "data.xml" from ss2:    <xsl:value-of select="document('data.xml')"/>
  "../data.xml" from ss2: <xsl:value-of select="document('../data.xml')"/>


T:\test\dir1>xt ss1.xsl ss1.xsl

  "data.xml" from ss2:    dir2\data.xml
  "../data.xml" from ss2: dir1\data.xml
T:\test\dir1>saxon ss1.xsl ss1.xsl

  "data.xml" from ss2:    dir2\data.xml
  "../data.xml" from ss2: dir1\data.xml

Next public European delivery:  3-day XSLT/2-day XSL-FO 2004-01-??
Instructor-led on-site corporate, government & user group training
for XSLT and XSL-FO world-wide:  please contact us for the details

G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6                       Definitive XSLT and XPath
ISBN 0-13-140374-5                               Definitive XSL-FO
ISBN 1-894049-08-X   Practical Transformation Using XSLT and XPath
ISBN 1-894049-11-X               Practical Formatting Using XSL-FO
Member of the XML Guild of Practitioners:     http://XMLGuild.info
Male Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc

XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list

Current Thread