For example, here is an implementation of the "file_exists()" PHP function.
<?php
// Definition of the handler
function mySchemeHandler($processor, $scheme, $rest)
{
$rest = substr($rest,1); // to remove the first / automatically added by the engine
if ($scheme == 'file_exists') {
// result is embedded in a small xml string
return '<?xml version="1.0" encoding="UTF-8"?><root>' . (file_exists($rest) ? 'true' : 'false') . '</root>';
}
}
$SchemeHandlerArray = array('get_all' => 'mySchemeHandler');
// Start the engine
$params = array();
$xh = xslt_create();
xslt_set_scheme_handlers($xh, $SchemeHandlerArray);
$result = xslt_process($xh, "myFile.xml", "myFile.xsl", NULL, array(), $params);
xslt_free($xh);
echo $result;
?>
Then, inside the stylesheet, you can test whether a certain file exists with:
<xsl:if test="document('file_exists:anotherXMLfile.xml')/root='true'">
<!-- The file exist -->
</xsl:if>