Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 software programmers and website developers 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 developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 21st, 2008, 03:09 PM
Registered User
 
Join Date: Nov 2008
Location: , , .
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...
Reply With Quote
  #2 (permalink)  
Old November 22nd, 2008, 08:23 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
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
Reply With Quote
  #3 (permalink)  
Old November 22nd, 2008, 08:43 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
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
Reply With Quote
  #4 (permalink)  
Old November 23rd, 2008, 03:44 PM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
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


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:33 AM.


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