xsl-list
[Top] [All Lists]

Re: [xsl] How could I detect/prevent a file not found exception in document()?

2019-02-05 07:35:33
On 05.02.2019 14:21, Trevor Nicholls trevor(_at_)castingthevoid(_dot_)com wrote:

A set of templates which are used to fill in the clickable text of a cross-reference are occasionally failing for me with a "file not found" exception. The processor we are using for this is Saxon but I'm hoping that there may be a way to code round the problem that is not processor-specific, so I am posting the relevant part of it here rather than on the Saxon list.

The stylesheet containing these templates is currently XSL 1.0 because an extensive array of stylesheets include it, and some of them have to be XSL 1.0. But I could easily do a separate XSL 2.0 version if that helped avoid this issue.

In general Saxon 9 supports the function doc-available, like any other processor supporting XSLT/XPath 2 and later so using e.g.


      <!-- can't find the file/id, so need a bit of magic: use the cache document from the previous build -->

       <xsl:otherwise>

         <xsl:variable name="cachefile">

           <xsl:call-template name="cache-filename">

             <xsl:with-param name="pathname" select="$linkfile" />

           </xsl:call-template>

         </xsl:variable>

         <xsl:variable name="cachedlink">

           <!-- doc TWO -->

   <xsl:if test="doc-available($cachefile)">

           <xsl:for-each select="document($cachefile,/)">

might help.

With Saxon 9.8 or 9.9 and XSLT 3 you would also be able to use `xsl:try/catch"
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>