[xsl] What should the document-uri() function return for a re-directed URL?

Subject: [xsl] What should the document-uri() function return for a re-directed URL?
From: Colin Paul Adams <colin@xxxxxxxxxxxxxxxxxx>
Date: 26 Nov 2006 20:26:22 +0000
I'm not 100% clear what the answer to this should be.

The data model defines the document-uri accessor as:

"the absolute URI of the resource from which the Document Node was
constructed, if the absolute URI is available."

In the case of the base-uri, it is certainly the re-directed URL that
should be returned. I'm not clear in my mind if the same holds for the

Here's a test stylesheet to illustrate the point:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";

<xsl:output method="text"/>
<xsl:template name="initial">
 <xsl:variable name="doc" select="doc('http://colina.demon.co.uk/test.html')"/>

 <xsl:text>URI used to call document is:
 <xsl:value-of select="document-uri ($doc)"/>
 <xsl:text>Base URI of document is:
 <xsl:value-of select="base-uri ($doc)"/>
 <xsl:text>Does document-uri() eq http://colina.demon.co.uk/test.html?:
<xsl:value-of select="document-uri($doc) eq 'http://colina.demon.co.uk/test.html'"/>
 <xsl:text>Does document-uri() eq http://colina.demon.co.uk/test/test.html?:
<xsl:value-of select="document-uri($doc) eq 'http://colina.demon.co.uk/test/test.html'"/>
 <xsl:text>Does $doc eq document-uri($doc)?:
<xsl:value-of select="$doc eq doc(document-uri($doc))"/>



Using gestalt, the output I get is:

URI used to call document is:
Base URI of document is:
Does document-uri() eq http://colina.demon.co.uk/test.html?:
Does document-uri() eq http://colina.demon.co.uk/test/test.html?:
Does $doc eq document-uri($doc)?:

(I have set up my apache server to do the re-direct for the purposes
of testing this, hence base-uri() is not the same as the original
argument to doc).

The last test is the guarenteed semantics for when document-uri()
returns anything but an empty sequence, so this is OK.

I guess the rest is OK too - I wish I had tested this before proposed
recommendation, but I only thought about it this weekend.

When in doubt, I usually test also with Saxon, but Saxon 8.8B for
Java, on my machine gives:

Error on line 7 of file:/home/colin/gestalt/test_http_redirect.xsl:
  FODC0005: Stream closed.
Error on line 7 of file:/home/colin/gestalt/test_http_redirect.xsl:
  FODC0005: Failed to load document http://colina.demon.co.uk/test.html
Transformation failed: Run-time errors were reported

Whether this is a problem with Saxon itself, or the JVM I don't know
(it may well be arguable).

What does Saxon.NET give?
Colin Adams
Preston Lancashire

Current Thread