Discussion:
Confusion about using xml:base in xsl:stylesheet element
Bill French
2009-08-06 19:04:50 UTC
Permalink
Hi all,

I have the following directory/file structure:

common/
|- core.xsl
a/
|- 1.xsl
docs/
|- document.xml

That is, three directories (common, a, and docs), each with one file
(core.xsl, 1.xsl, and document.xsl, respectively).

Further, let's say that these directories live at the absolute path
file:///z:/work/dev/xslt. In core.xsl, I have this:

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

<xsl:include href="a/1.xsl"/>

<xsl:variable name="doc"
select="document('docs/doc.xml')"></xsl:variable>

<xsl:template match="node() | @*">
<xsl:apply-templates select="node() | @*"/>
</xsl:template>

</xsl:stylesheet>

(Notice the xml:base attribute on the xsl:stylesheet element.)

Executing a transformation in the following way:

***@halibut /cygdrive/z/work/dev/xslt
$ java -jar saxon8.jar data.xml common/core.xsl

produces the error

Error at xsl:include on line 5 of file:/z:/work/dev/xslt/common/core.xsl:
XTSE0165: java.io.FileNotFoundException: z:\work\dev\a\1.xsl (The
system cannot find the path specified)
Failed to compile stylesheet. 1 error detected.


If I comment out the xsl:include, the call to the document() function
produces a similar error.

Recoverable error on line 7 of file:/z:/work/dev/xslt/common/core.xsl:
FODC0005: java.io.FileNotFoundException: z:\work\dev\docs\doc.xml
(The system cannot find the path specified)
Error on line 7 of file:/z:/work/dev/xslt/common/core.xsl:
FODC0005: Failed to load document docs/doc.xml
Transformation failed: Run-time errors were reported

In both cases, the processor seems to be setting the base-uri to
file:///z:/work/dev, not file:///z:/work/dev/xslt as is specified.
However, when I change the stylesheet to the following:

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

<xsl:include href="../a/1.xsl"/>

<xsl:variable name="doc"
select="doc('../docs/doc.xml')"></xsl:variable>

<xsl:template match="node() | @*">
<xsl:apply-templates select="node() | @*"/>
<xsl:value-of select="$doc"/>
</xsl:template>

</xsl:stylesheet>

(I've removed xml:base and changed both the xsl:include's href attribute
and the argument to the document function.) The transformation now runs
as expected. What am I misunderstanding? I thought xml:base provided a
baseline for all URIs/paths. Is that not the case?

Thanks in advance for any help!

Regards

--Bill



--~------------------------------------------------------------------
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-***@lists.mulberrytech.com>
--~--
G. Ken Holman
2009-08-06 20:06:49 UTC
Permalink
Post by Bill French
Hi all,
common/
|- core.xsl
a/
|- 1.xsl
docs/
|- document.xml
That is, three directories (common, a, and docs), each with one file
(core.xsl, 1.xsl, and document.xsl, respectively).
Further, let's say that these directories live at the absolute path
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xml:base="file:///z:/work/dev/xslt">
I'm pretty sure you need "file:///z:/work/dev/xslt/" because what you
have specified now is a file named "xslt" in the "dev/" directory,
not what you want.

I hope this helps.

. . . . . . . . . Ken

--
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:

Video overview:

G. Ken Holman mailto:***@CraneSoftwrights.com
Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers: http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
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-***@lists.mulberrytech.com>
--~--
Bill French
2009-08-06 22:04:12 UTC
Permalink
Thanks very much for your help, Ken. That was the problem.

As a follow up, including a xml:base attribute on xsl:stylesheet will
alter the base URI for any XSLT/XPath functions/instructions/etc. that
use a file path, right? E.g., the document() function, the xsl:include
and xsl:import instructions, and so forth?

Regards,

--Bill
Post by G. Ken Holman
Post by Bill French
Hi all,
common/
|- core.xsl
a/
|- 1.xsl
docs/
|- document.xml
That is, three directories (common, a, and docs), each with one file
(core.xsl, 1.xsl, and document.xsl, respectively).
Further, let's say that these directories live at the absolute path
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xml:base="file:///z:/work/dev/xslt">
I'm pretty sure you need "file:///z:/work/dev/xslt/" because what you
have specified now is a file named "xslt" in the "dev/" directory,
not what you want.
I hope this helps.
. . . . . . . . . Ken
--
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson: http://youtu.be/PrNjJCh7Ppg
Video overview: http://youtu.be/VTiodiij6gE
Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers: http://www.CraneSoftwrights.com/legal
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--~--
--~------------------------------------------------------------------
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-***@lists.mulberrytech.com>
--~--
Michael Kay
2009-08-06 22:21:21 UTC
Permalink
Post by Bill French
As a follow up, including a xml:base attribute on
xsl:stylesheet will alter the base URI for any XSLT/XPath
functions/instructions/etc. that use a file path, right?
E.g., the document() function, the xsl:include and xsl:import
instructions, and so forth?
Yes: also static-base-uri(), relative collation URIs, etc.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay


--~------------------------------------------------------------------
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-***@lists.mulberrytech.com>
--~--

Loading...