[xsl] Test if an (image) file exists

Subject: [xsl] Test if an (image) file exists
From: "Derek Revill" <derek@xxxxxxxxxxxxxxxxxx>
Date: Wed, 8 Jun 2005 12:52:40 +0100

I'd like to test if image files exist in a target directory on my file
system before adding links to them in html output (I need to check on
$filename.jpg or $filename.gif and other variations.) Should I use a Java
extension function in my XSLT or are there now better ways to do this with
in-built XSLT functions, using unparsed-text() for example? 

I'm have an XSLT 2.0 sheet and I'm running Saxon 8.4 (with Java VM 1.4). 

I'm no Java programmer so an exact code snippet of a template calling Java
would be great. I turned up this older example in the archive:


<xsl:template name="file_util_check_directory" xmlns:file="java.io.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" -->

But if I pass this template a filename (xs:string) I get the following

"There is more than one method matching the function call file:new, and
there is insufficient type information to determine which one should be

Any help appreciated.



Current Thread