[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Global variable reads in the input XML document using the document() function ... sometimes it works, sometimes it doesn't


Subject: Re: [xsl] Global variable reads in the input XML document using the document() function ... sometimes it works, sometimes it doesn't
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sat, 27 Oct 2012 09:29:02 -0400

At 2012-10-27 13:11 +0000, Costello, Roger L. wrote:
Hi Folks,

I have an XSLT program which has a global variable that uses the document() function to read in the XML document that the program was invoked with:

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

<xsl:variable name="file" select="document(.)"/>

    <xsl:template match="/">
        ...
    </xsl:template>

</xsl:stylesheet>
------------------------------------------------------

On some input XML documents that XSLT program works, and on others I get a horrific error message such as this:

FODC0002: Exception thrown by URIResolver: Invalid relative URI
{\n\t\t\t\tThis%20is%20an%20ann...}: Illegal character in path at index 0:

Sure it's invalid, it begins with a newline character.


It appears that the problem is with this statement:

<xsl:variable name="file" select="document(.)"/>

Right ... you are sking the processor to take the text value of the input file and pass that to the document() function as a URI string to open.


Sometimes the document() function finds the input XML file and sometimes it doesn't.

Why?

Because you are opening the stylesheet with an XML file whose text value is or is not a valid URI. Certainly a newline and a bunch of tab characters and "This is an..." is not a valid URI, just as the message indicates.


I solved the problem by passing into the XSLT program the filename of the input XML file and then invoking document() with that filename.

Fine ... that is a nice delimited string.


But I'd like to understand why the other approach doesn't work.

Because you are passing the text value of the entire input document as a URI.


What is it you really wanted from your input file? Is it perhaps a descendent element somewhere that has the URI that you want to open?

I hope this helps.

. . . . . . . . Ken

--
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/s/
G. Ken Holman                   mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal


Current Thread
Keywords