xsl-list
[Top] [All Lists]

RE: handling failed document() invocations

2002-10-30 04:21:33

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(_dot_)H(_dot_)Kay(_at_)ntlworld(_dot_)com
work: Michael(_dot_)Kay(_at_)softwareag(_dot_)com 


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