Re: [xsl] Referring to stylesheet itself, possible in XSLT 1.0, but how in XSLT 2.0?

Subject: Re: [xsl] Referring to stylesheet itself, possible in XSLT 1.0, but how in XSLT 2.0?
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Tue, 17 Oct 2006 13:44:30 +0200
Michael Kay wrote:
I understand, but it really just said "Transformation failed". Without any descriptive error, warning or whatever.
That's a bit puzzling. Calling document() with a URI that doesn't exist is a
recoverable error.

It was puzzling me too. I use Oxygen's Eclipse plugin for testing the XSLT. Normally it simply lists all the errors. Now it just said "Transformation failed". I learned something: try it outside of the IDE box. The following happens:


With this stylesheet:
---------------------
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0">
<xsl:template match="/">
1) <xsl:value-of select="document-uri(document(''))"></xsl:value-of>
2) <xsl:value-of select="static-base-uri()"></xsl:value-of>
3) <xsl:value-of select="base-uri(.)"></xsl:value-of>
</xsl:template>
</xsl:stylesheet>


This output:
------------
<?xml version="1.0" encoding="UTF-8"?>
       1) file:/D:/Workspaces/Eclipse/etc/def/config/test.xslt
       2) file:/D:/Workspaces/Eclipse/ect/def/config/test.xslt
       3) file:/D:/Workspaces/Eclipse/etc/def/config/test.xml


With this stylesheet: --------------------- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0" xml:base="../.."> <xsl:template match="/"> 1) <xsl:value-of select="document-uri(document(''))"></xsl:value-of> 2) <xsl:value-of select="static-base-uri()"></xsl:value-of> 3) <xsl:value-of select="base-uri(.)"></xsl:value-of> </xsl:template> </xsl:stylesheet>

This output:
------------
Error on line 1 column 1 of file:/D:/Workspaces/Eclipse/etc/:
SXXP0003: Error reported by XML parser: Content is not allowed in prolog.
Recoverable error on line 5 of file:/D:/Workspaces/Eclipse/etc/def/config/test.xslt:
FODC0005: org.xml.sax.SAXParseException: Content is not allowed in prolog.
<?xml version="1.0" encoding="UTF-8"?>
1)
2) file:/D:/Workspaces/Eclipse/etc/
3) file:/D:/Workspaces/Eclipse/etc/test.xml




I believe in the light of what all people said on this subject, this behavior is to be expected.

Try putting xml:base at the level of the stylesheet where you need it, e.g.
on a template rule, and have a global variable

The xml:base was used to make xsl:import easier. I did not want to add it to each xsl:import statement. But I guess, I'd have to decide on the pros and cons of either technique. At least I understand now what's happening.


Current Thread