Re: how to test if a file exists ?

Subject: Re: how to test if a file exists ?
From: Warren Hedley <w.hedley@xxxxxxxxxxxxxx>
Date: Thu, 29 Jun 2000 09:58:34 -0400
Jean-Claude Tarby wrote:
> I want to include links to graphic files in a html document which is
> produced by a stylesheet, but I want to put the link only if the graphic
> file exists on the hard disk. How to do that ?

You have to use an extension function - the following syntax will
work in both Saxon and XT. You can actually use it to reference
any external Java class, but you're pretty much guaranteed that will always be available!

I use this template to check if a directory exists, and if not,
to create it. You can easily adapt it to your problem.

<xsl:template name="file_util_check_directory" xmlns:file="">
  <xsl:param name="filename" />
  <xsl:variable name="directory"
                select="file:new(file:getParent(file:new($filename)))" />
  <xsl:if test="not(file:exists($directory))">
      <xsl:when test="file:mkdirs($directory)">
          <xsl:text>Creating directory `</xsl:text>
          <xsl:value-of select="file:getPath($directory)" />
          <xsl:text>WARNING : unable to create directory `</xsl:text>
          <xsl:value-of select="file:getPath($directory)" />
</xsl:template> <!-- name="file_util_check_directory" -->

Warren Hedley
Department of Engineering Science
Auckland University
New Zealand

 XSL-List info and archive:

Current Thread