RE: [xsl] mystery #2: testing document() without failure

Subject: RE: [xsl] mystery #2: testing document() without failure
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Sat, 13 Apr 2002 16:31:59 +0100
> So is it wrong to rely on something like (if processor
> independence is
> important):
>
> <xsl:variable name="test" select="document('test.xml')/test"/>
> <xsl:choose>
>    <xsl:when test="boolean($test)">
>       <xsl:apply-templates select="$test"/>
>    </xsl:when>
>    <xsl:otherwise>
>       <!-- error display -->
>    </xsl:otherwise>
> </xsl:choose>
>
> it works in saxon.
>
Yes, it's explicitly implementation-defined what happens when the document
referred to by the document() function doesn't exist. Either you get an
error, or you get an empty node-set.

Saxon gives you a user option to choose whether the error is fatal or not
(this is a global switch that applies to all recoverable dynamic errors, not
to this one explicitly). There are three settings: ignore the error and take
the prescribed recovery action; issue a warning message and take the
recovery action; produce a fatal error and stop. But there's no portable way
of setting such options.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread