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 element:
<test>
<location href="stuff/other.xml" />
</test>
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), .)" />
</xsl:template>
Good.
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(.)" />
</xsl:template>
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:variable>
<xsl:sequence select="$result/*" />
</xsl:function>
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/*)" />
</xsl:template>
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?
/Roger
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--