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

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
java test file exists
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
java.io.File 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="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" -->

-- 
Warren Hedley
Department of Engineering Science
Auckland University
New Zealand


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.