|
|
 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other programmers’ questions, win occasional prizes given to our best members, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
|
 |

November 21st, 2008, 03:09 PM
|
|
Registered User
|
|
Join Date: Nov 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
XSLT Check if directory exist
Hi,
Is there a way to check if a certain directory in unix exists using xslt?
Sample:
//phome/folder/subolder1
//phome/folder/subolder2
//phome/folder/subolder3
//phome/folder/
If found this in p2p and tested it but it doesnt seem to work:
(image.xsl)
<xsl:template name="xml-file-exists">
<xsl:param name="url"/>
<xsl:variable name="test-url">//(unix_diretory)<xsl:value-of select="$url"/>
</xsl:variable>
<xsl:copy-of select="document($test-url)//file"/>
</xsl:template>
<xsl:variable name="file-exists">
<xsl:call-template name="xml-file-exists">
<xsl:with-param name="url" select="$options.xml"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="$file-exists='true'">
...xsl code using document()...
</xsl:when>
<xsl:otherwise>
...xsl code without document()
</xsl:otherwise>
</xsl:choose>
I need to check if the folder exist in unix and if it is it will be uploaded in a certain site using ant:
<ftsfileupload verbose="no" failOnError="no" ftsURL="${ftsURL}" stylesheet="${images}" rootName="root" generateIdx="true" >
<fileset dir="${graphicsDir}" includes="**/*"/>
</ftsfileupload>
thanks...
|

November 22nd, 2008, 08:23 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Location: Germany
Posts: 701
Thanks: 0
Thanked 109 Times in 108 Posts
|
|
I don't think pure XSLT can check for the existance of a file or folder. You need an extension function or extension object for that. How you do that exactly is then highly processor dependent.
--
Martin Honnen
Microsoft MVP - XML
|

November 22nd, 2008, 08:43 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Location: Germany
Posts: 701
Thanks: 0
Thanked 109 Times in 108 Posts
|
|
Just to be clear, if you want to check whether an XML document can be loaded, then XSLT 2.0 has http://www.w3.org/TR/xpath-functions...-doc-available. But I don't think that helps to check for the existance of a folder/directory.
--
Martin Honnen
Microsoft MVP - XML
|

November 23rd, 2008, 03:44 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Location: , , .
Posts: 374
Thanks: 14
Thanked 0 Times in 0 Posts
|
|
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
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |