Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Check whether a file exists with XSLT2 (a Java extension -powered function)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl=""
exclude-result-prefixes="java xs">
<xsl:function name="java:file-exists" xmlns:file="" as="xs:boolean">
<xsl:param name="file" as="xs:string"/>
<xsl:param name="base-uri" as="xs:string"/>
<xsl:variable name="absolute-uri" select="resolve-uri($file, $base-uri)" as="xs:anyURI"/>
<xsl:sequence select="file:exists(file:new($absolute-uri))"/>

This comment has been minimized.

Copy link
Owner Author

commented Jan 14, 2013

Use like this:

<xsl:if test="java:file-exists($filename, base-uri())">
  <!-- ... -->

This comment has been minimized.

Copy link

commented Jun 21, 2013

Works beautifully. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.