 |
| 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
|
|
|
|

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

June 28th, 2010, 01:49 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
You need the collection function which is available in version 2.0.
|
|
The Following User Says Thank You to joefawcett For This Useful Post:
|
|
|

June 28th, 2010, 02:43 AM
|
|
Authorized User
|
|
Join Date: May 2010
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by joefawcett
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! 
|
|

June 28th, 2010, 02:56 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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.
|
|

June 28th, 2010, 03:34 AM
|
|
Authorized User
|
|
Join Date: May 2010
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

June 28th, 2010, 03:59 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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.
|
|

June 28th, 2010, 04:32 AM
|
|
Authorized User
|
|
Join Date: May 2010
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

June 28th, 2010, 04:51 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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
|
|
The Following User Says Thank You to samjudson For This Useful Post:
|
|
|

June 28th, 2010, 04:54 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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
|
|

June 28th, 2010, 04:39 PM
|
|
Authorized User
|
|
Join Date: May 2010
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|
 |