[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Test if an (image) file exists

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

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:

http://www.biglist.com/lists/xsl-list/archives/200006/msg01332.html

<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:choose>
      <xsl:when test="file:mkdirs($directory)">
        <xsl:message>
          <xsl:text>Creating directory `</xsl:text>
          <xsl:value-of select="file:getPath($directory)" />
          <xsl:text>'</xsl:text>
        </xsl:message>
      </xsl:when>
      <xsl:otherwise>
        <xsl:message>
          <xsl:text>WARNING : unable to create directory `</xsl:text>
          <xsl:value-of select="file:getPath($directory)" />
          <xsl:text>'.</xsl:text>
        </xsl:message>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:if>
</xsl:template> <!-- name="file_util_check_directory" -->

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

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

Any help appreciated.

Derek

--
http://www.revill.demon.co.uk

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.