[xsl] Is there a way to assign a base URI to a document?

Subject: [xsl] Is there a way to assign a base URI to a document?
From: "Costello, Roger L." <costello@xxxxxxxxx>
Date: Thu, 25 Aug 2011 14:26:33 -0400
Hi Folks,

Is there a way to assign a base URI to a document?

Allow me to explain.

Here is an XML document. Notice the relative reference in the location

    <location href="stuff/other.xml" />

If my XSLT code inputs that XML document, it can get the document at that
relative reference:

    <xsl:template match="test">

            <xsl:sequence select="document(string(location/@href), .)" />



Now, suppose that instead of doing that, my XSLT code calls a function and
passes it the XML document:

    <xsl:template match="test">

            <xsl:variable name="result" select="f:identity(.)" />


The function creates a variable, inside the variable it outputs the XML
document, and then it outputs the value of the variable:

    <xsl:function name="f:identity" as="element()">
        <xsl:param name="doc" as="element()" />

        <xsl:variable name="result">
            <xsl:sequence select="$doc" />

        <xsl:sequence select="$result/*" />


Oh, that function is in a separate XSLT file and is in its own folder. Here's
how it is included:

    <xsl:include href="folder/identity.xsl" />

The document returned by the function is identical to the input XML document.
So, my code now attempts to access the document at location/@href:

    <xsl:template match="test">

            <xsl:variable name="new-xml" select="f:identity(.)" />

            <xsl:sequence select="document(string($new-xml//location/@href),
$new-xml/*)" />


Unfortunately, FILE NOT FOUND is the result.

The reason? The base URI of new-xml is different than the base URI of the
original XML document. Thus, location/@href is attempting to reference
stuff/other.xml relative to the new-xml's base URI. And that's wrong.

For reasons I will not explain, I cannot simply use the XML document as the
second argument to the document function:

     document(string($new-xml//location/@href), .)

I would really like to assign to $new-xml a base URI. Is there a way to do
that? If not, what's the best way to deal with this situation?


Current Thread