Table of Contents

File Utility Functions
File Existence Extension Function
File Length Function
File Modification Time Function
Current Date & Time Function
[ You are here: XTF -> Tag Reference -> File Utility Functions ]

File Utility Functions

XTF provides a number of functions that stylesheets can use to check attributes of a file in the local filesystem. See the XTF Programming Guide for a description and examples.

File Existence Extension Function

This extension function can be used within a stylesheet to determine whether a particular file exists on the filesystem, like this:
<xsl:if test="FileUtils:exists(FilePath)"></xsl:if>
where
FileUtils: is a namespace prefix identifying this set of Saxon extension functions. The namespace URI for this prefix must be: java:org.cdlib.xtf.xslt.FileUtils.
FilePath specifies the relative or absolute path to the file in question. If a relative path is specified, it will be resolved in relation to the stylesheet that calls the function.
The extension function returns the boolean value true if the file is readable by the stylesheet, or false if not.

File Length Function

This extension function can be used within a stylesheet to determine the length (in bytes) of a particular file exists on the filesystem, like this:
<xsl:variable name="myFileLen" select="FileUtils:length(FilePath)"></xsl:variable>
where
FileUtils: is a namespace prefix identifying this set of Saxon extension functions. The namespace URI for this prefix must be: java:org.cdlib.xtf.xslt.FileUtils.
FilePath specifies the relative or absolute path to the file in question. If a relative path is specified, it will be resolved in relation to the stylesheet that calls the function.
The extension function returns the length, in bytes, of the specified file, or -1 if the file cannot be read.

File Modification Time Function

This extension function can be used within a stylesheet to find out when a particular file was last modified, like this:
<xsl:variable name="myModTime"
              select="FileUtils:lastModified(FilePath, DateFormat)"></xsl:variable>
where
FileUtils: is a namespace prefix identifying this set of Saxon extension functions. The namespace URI for this prefix must be: java:org.cdlib.xtf.xslt.FileUtils.
FilePath specifies the relative or absolute path to the file in question. If a relative path is specified, it will be resolved in relation to the stylesheet that calls the function.
DateFormat is a string representing the format that the date and/or time should be returned in. This uses codes from Java's SimpleDateFormat class such as yyyy-MM-dd:HH:mm:ss.
The extension function returns a formatted version of the date and/or time (depending on format) that a given file was last modified. This can be useful for detecting which files are newer than others, processing all files newer than a certain date, etc.

Current Date & Time Function

This extension function can be used within a stylesheet to find out the current date and time known to the system, like this:
<xsl:variable name="myTime"
              select="FileUtils:curDateTime(DateFormat)"></xsl:variable>
where
FileUtils: is a namespace prefix identifying this set of Saxon extension functions. The namespace URI for this prefix must be: java:org.cdlib.xtf.xslt.FileUtils.
DateFormat is a string representing the format that the date and/or time should be returned in. This uses codes from Java's SimpleDateFormat class such as yyyy-MM-dd:HH:mm:ss.
The extension function returns a formatted version of the current date and/or time (depending on format). This can be useful for constructing time-based queries, displaying the time or date on a result page, etc.