Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 21st, 2008, 03:09 PM
Registered User
 
Join Date: Nov 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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...
 
Old November 22nd, 2008, 08:23 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

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
 
Old November 22nd, 2008, 08:43 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

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
 
Old November 23rd, 2008, 03:44 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

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







Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot create record, directory exist auxiora_nemesis PHP Databases 1 April 13th, 2008 11:04 PM
check for image field exist goldenstate ASP.NET 2.0 Basics 2 May 22nd, 2007 12:36 PM
Check to make sure a directory exists stonesbg ASP.NET 2.0 Basics 3 January 18th, 2007 03:25 PM
check for directory, or create new if not found amerk20 VB How-To 1 April 8th, 2005 12:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.