With XSLT 2.0, you can use the doc-available(string? $uri) function.
On 8/28/06, Laky Tang <tulaky(_at_)yahoo(_dot_)com> wrote:
I have followed various postings and I am led to
believe that XSL does not have any built in capability
to check if a file exists or not. I read there is a
way to check using extensions, but the following
example gives me an error "Namespace 'java.io.File'
does not contain any functions" in IE and XML spy. It
works incorrectly in Firefox / Flock by always saying
the file does not exist (even if it does). Changing
XSLT 1.0 to 2.0 did not make any difference.
I find it quite ironic that XSLT lacks this basic
capability to check if a file exists-or-not given its
main use is in working with XML documents (and files).
If there is a simple way to gracefully handle the
condition, can somebody please point me in the right
direction?
Thanks,
-Tulaky
Example adapted from another posting:
------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:h="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<!-- my other templates go here which call this with
the filename-->
<xsl:template name="file_exists"
xmlns:file="java.io.File">
<xsl:param name="filename" />
<xsl:if test="not(file:exists($filename))">
file <xsl:value-of select="$filename"/> does not
exist!
</xsl:if>
</xsl:template>
</xsl:stylesheet>
--
Regards,
Mukul Gandhi
http://gandhimukul.tripod.com
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--