Hi,
If you need to check if a file exist, use an extension. What type of extension you use depends on the xslt processor. In the below example, I use Saxon 9.4, which use java.
Create and compile the java class:
Code:
import java.io.File;
public class FileExist {
private static boolean exist;
public static boolean fileExist(String myfile) {
exist = new File(myfile).exists();
return exist;
}
}
XML:
Code:
<root>
<member>2008-01-01</member>
<member>2009-06-23</member>
<file>C:\\temp2\\chap1.xml</file>
</root>
xslt:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ACM="java:FileExist">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head>
</head>
<body>
<xsl:for-each select="root/file">
<h1>
<xsl:value-of select="ACM:fileExist(.)"/>
</h1>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Windows Command line to run:
Code:
@echo off
:: Run with extensions
:: place all classes in classes folder in your saxon direcory
java -classpath ./classes;saxon9.jar net.sf.saxon.Transform -s:"C:\input.xml" -xsl:"C:\java_ext_file_exist.xslt" -o:output.html & pause