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 June 27th, 2010, 11:34 PM
Authorized User
 
Join Date: May 2010
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reading from Filesystem

Is there a way to read files from the filesystem via XSL?

I have a directory of files for which I want to create an XML file using those file names.

I've done this many times in PHP but am outputting XML and using XSL to then process the XML. Trying to determine if I can do this w/o PHP in the mix.

Thanks.
Robert
 
Old June 28th, 2010, 01:49 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You need the collection function which is available in version 2.0.
__________________
Joe
http://joe.fawcett.name/
The Following User Says Thank You to joefawcett For This Useful Post:
tsmets (July 12th, 2010)
 
Old June 28th, 2010, 02:43 AM
Authorized User
 
Join Date: May 2010
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Smile

Quote:
Originally Posted by joefawcett View Post
You need the collection function which is available in version 2.0.
I did see the Collection function earlier but was under the impression that I'd have add extensions. This is now native to XSLT 2.0?

In any event, I found and tried the following example, which reads files from directory. I get a very generic error "Error! An error occurred on line 5 in /html/CollectionTest.php Error no: Error :

XSL Code:
<xsl:for-each select="collection(iri-to-uri('../images/?select=*.*'))">
<dv><xsl:value-of select="position()"/> </div>
</xsl:for-each>

The intention is simply to read the all files from the 'images' dir and output the position.

Any ideas why this might fail? How would I determine if my web host uses XSLT2.0?

Also any other references w/eamples would be appreciated!
 
Old June 28th, 2010, 02:56 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

If you are running the XSLT from inside php then I doubt you will have an XSLT 2.0 processor.

And if all you want is the filenames, not the actual contents of the file then you will probably have to write an extension function - I'm unsure how you do this in whatever XSLT processor PHP is using.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old June 28th, 2010, 03:34 AM
Authorized User
 
Join Date: May 2010
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's the PHP function

function processXSL_UsingXML($xslToUse, $xmlToUse)
{

$xp = xslt_create();
xslt_set_error_handler($processor, "errorHandler");
xslt_set_log($xp, true);
xslt_set_log($xp, 'debugRJF.log');

# Process the XSL
$result = xslt_process($xp, $xmlToUse, $xslToUse, NULL, array());

if (!$result) handleError();
print $result;
xslt_free($xp);
}

Not sure why this pattern of firing off XSL would dicate the verion of XSL i'm using.

Any examples of using <collection> for those that have worked?
 
Old June 28th, 2010, 03:59 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

It's not how you are firing off the XSLT that dictates the version of XSLT you are using, just that there are very few XSLT processors that support XSLT 2.0, and none of them are built into PHP that I am aware of.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old June 28th, 2010, 04:32 AM
Authorized User
 
Join Date: May 2010
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmm... guess I'm confused about this. I'm using php commands to to gather the xml/xsl and firing off the transformation. The transformation is happening on my server. Wouldn't the version of XSL that is running on server dictate the version?

My PHPINFO shows this http://share.rjfweb.com/phpinfo.php

So botton line is, if I only have support for XSLT 1.0 then I cannot use fn:collection. And there are no other alternatives?

Thanks, Sam.
 
Old June 28th, 2010, 04:51 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The only XSLT 2.0 processors I am aware of are Saxon (java based), AltovaXML (windows only) and Gestalt (Eiffel?).

Within XSLT 1.0 there is no way to natively do what you are wanting so you are either going to have to pass the information in to the XSLT processor as a variable, or call an external function from within your XSLT.

There is some documentation on the latter here: http://uk.php.net/manual/en/xsltproc...pfunctions.php
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
tsmets (July 12th, 2010)
 
Old June 28th, 2010, 04:54 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You are using PHP to create the XSLT processor so you get the PHP implementation by default. I don't quite follow what you're attempting. Originally you said you wanted to remove PHP from the mix so I suggested using XSLT 2.0, such as Saxon. Now you seem to be trying to do it with PHP anyway. You can use Saxon from PHP I believe, see this link: http://php.net/manual/en/book.xsl.php
__________________
Joe
http://joe.fawcett.name/
 
Old June 28th, 2010, 04:39 PM
Authorized User
 
Join Date: May 2010
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the suggestions. I read through and tried them, however they don't work on my host server and I don't have control over the PHP configuration - i.e. ini files (as suggested in docs).

I vaguely remember trying this once before with same results. I checked PHP config - PHP Version 4.4.9 without necessary DOM extensions. http://share.rjfweb.com/phpinfo.php

Thanks again for your help.
Rob





Similar Threads
Thread Thread Starter Forum Replies Last Post
use My.Computer.FileSystem.ReadAllText in webdesin abc052107 Visual Studio 2005 4 July 5th, 2007 08:52 PM
Problem with code: My.Computer.FileSystem Sporty BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 2 April 23rd, 2007 05:05 AM
Problem with code: My.Computer.FileSystem Sporty Visual Basic 2005 Basics 0 March 14th, 2007 03:52 PM
Using The FileSystem Object Ben Horne Classic ASP Basics 1 December 1st, 2003 09:21 PM





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