|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: how to test if a 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








