[xsl] coping with missing external document

Subject: [xsl] coping with missing external document
From: "Trevor Nicholls" <trevor@xxxxxxxxxxxxxxxxxx>
Date: Thu, 31 Jul 2008 18:14:06 +1200
I have a v1.0 stylesheet which fills in cross-reference text by looking up
an external document, using the following template rule:

 <!-- external cross references -->
 <xsl:template match="jump[@srcfile]">
  <xsl:variable name="jfil" select="substring-before(@srcfile,'#')" />
  <xsl:variable name="jid" select="substring-after(@srcfile,'#')" />
  <xsl:copy>
   <xsl:attribute name="text">
    <xsl:for-each select="document($jfil,/)">
     <xsl:value-of select="normalize-space(id($jid))" />
    </xsl:for-each>
   </xsl:attribute>
  </xsl:copy>
 </xsl:template>

If the external document does not exist I would like the template to copy
the jump element and give it an empty text attribute, without generating an
error. However this isn't what happens when the stylesheet is run. If the
external document is missing the transformation stops with an error, which
is unfortunate because the main purpose of the stylesheet is to transform a
document written by FrameMaker so that it is translated from one schema to
another. If the transformation fails the document is left in an invalid
state. The XSL processor is Xalan.

Is there anything I can add to the template, or stylesheet, so that this
situation does not generate a fatal error?

Cheers
Trevor

Current Thread