RE: [xsl] handling failed document() invocations

Subject: RE: [xsl] handling failed document() invocations
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Wed, 30 Oct 2002 11:21:33 -0000
> The problem is there may not be a document there, which is an 
> OK state of affairs.  What is the xsl code idiom for 
> detecting when document() is unable to find a document at the 
> given location, and to handle this in a more meaningful way 
> than exiting on error?
> If it matters I'm using saxon 6.5.2.

The XSLT 1.0 spec says that the implementation can choose whether to
fail when document() can't find anything, or to recover by returning an
empty node-set. Unfortunately this doesn't really help you write
portable code.

In Saxon you can set the error handling options from the command line:

  -w0 recovers silently from recoverable errors
  -w1 (the default) gives a warning and then recovers
  -w2 gives a fatal error

You can also control it from the API.

This is a global switch that applies to all errors; you could also try
to write a JAXP ErrorListener that handles the specific error.

Another approach is to write your own URIResolver that finds the
document, it can return a dummy document if nothing is found. This is
probably the most portable solution.

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

 XSL-List info and archive:

Current Thread