Re: [xsl] should document-uri work like this?

Subject: Re: [xsl] should document-uri work like this?
From: Graydon <graydon@xxxxxxxxx>
Date: Sat, 1 Jan 2011 18:04:58 -0500
On Sat, Jan 01, 2011 at 02:30:20PM -0800, Fred Christian scripsit:
[snip]
> <xsl:variable name="folder" select="format-number(position(), '00')"/>
> <xsl:variable name="file">sp.html</xsl:variable>
> <xsl:variable name="wb">./<xsl:value-of
> select="$folder"/>/subfolder/index.xml</xsl:variable>
> <xsl:result-document href="./{$folder}/{$file}">
>  <xsl:variable name="thisdoc" select="document-uri(.)"/>
>  ==<xsl:value-of select="base-uri()" />-TEST-base-uri
>  ==<xsl:value-of select="$thisdoc" />-TEST-document-uri
>  ==<xsl:value-of select="$wb" />-TEST-wb
>  <xsl:if test="document($wb)">
>  <script language="javascript" src="whiteboards/links.js"/>
>  </xsl:if>
> </xsl:result-document>
[snip]
> Two questions here.
> - How do I get document-uri to work?

Remember that document-uri is the inverse of the doc function; it gives
you the document-uri property of a document node. (doc() gives you the
document node of the thing it finds at the URI you give it, if it can.)

If you call it on the context node in a global variable (which is what
that looks like) there isn't a context node, so the document-uri
property of a null sequence is the null sequence, but even if there _is_
a context node, if it's not the document node, you still won't get
anything back from document-uri().

So either use base-uri(), which will walk back up the various trees to
get the document node, or use document-uri(root(.)) if there really is
a context node defined, or use document-uri(/) if you want the document
URI in a global variable.

> - Once I do, should this idea work to make the document() function
> have a base-uri to resolve from?

Here I find myself unclear on what you're trying to do -- iterate over a
bunch of files?  That's what collection() is for, and will very likely
work better (if this is XSLT 2.0, which I think it has to be from
document-uri()) than trying to hand-code it.

-- Graydon

Current Thread