If you pass a node to the document function (for example document(@filename)), then the function takes the string value of the node, and if this is a relative URI, resolves it against the base URI of that node.
 
If you pass a string to the document function (for example document(concat("", @filename))) then the relative URI is resolved against the base URI of the stylesheet.
 
I imagine this accounts for the difference.
 
You could use the second argument of document() to change this:
 
document(concat("", @filename), @filename))
 
or you could use functions such as base-uri(), static-base-uri(), and resolve-uri() to control the URI resolution "by hand".
 
Michael Kay
http://www.saxonica.com/ 


From: martin.me.roberts@bt.com [mailto:martin.me.roberts@bt.com]
Sent: 25 April 2008 11:33
To: saxon-help@lists.sourceforge.net
Cc: mike@saxonica.com   
Subject: Finding documents

Hi,
  I am writing something that generates xsl fiels on the fly.  The input is a mapping document taht can refer to documents through an include.  these documents are to be local to the mapoing document not the xsl stylesheet that is processing the mapping file.
 
The following is a portion of my xsl sheet:
    <xsl:template match="include">
        <xsl:variable name="filename" select="concat($path,@filename)"/>
        <xsl:copy-of select="document($filename)/mapping/*"/>
    </xsl:template>
 
Path is declared as empty. 
 
I get a warning if I use the $filename that the file can not be found, but I get the correct results if I simply pass the attribute @filename to the document function.  Can you please explain what is happing and how I can get the desired result, i.e. find a file relative to the input file not the styulesheet?
 
Martin