php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53965 <xsl:include> cannot find files w/ relative paths when loaded w/ "file://"
Submitted: 2011-02-08 23:46 UTC Modified: 2013-12-02 14:05 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: clarkwise at gmail dot com Assigned: ab
Status: Closed Package: XSLT related
PHP Version: 5.2.17 OS: Windows XP
Private report: No CVE-ID:
 [2011-02-08 23:46 UTC] clarkwise at gmail dot com
Description:
------------
I upgraded from PHP 5.2.5 (using binaries from windows.php.net), and now the <xsl:include>s in some of my stylesheets stopped working. Testing each version in succession, I discovered that it worked up through 5.2.8 and does not work in 5.2.9+. I now get the following three errors for each <xsl:include>.

Warning: XSLTProcessor::importStylesheet(): I/O warning : failed to load external entity "file%3A/C%3A/xsltest/include.xsl" in C:\xsltest\xsl.php on line 11

Warning: XSLTProcessor::importStylesheet(): compilation error: file file%3A//C%3A/xsltest/collection.xsl line 3 element include in C:\xsltest\xsl.php on line 11

Warning: XSLTProcessor::importStylesheet(): xsl:include : unable to load file%3A/C%3A/xsltest/include.xsl in C:\xsltest\xsl.php on line 11

Interestingly, in the first and third
errors, it is displaying the file:// protocol with only one slash
instead of the correct two.

IMPORTANT NOTE: This problem only occurs when the primary XSL document is loaded with the "file://" protocol with one too few slashes. (See sample PHP file.) Correctly, there should be three slashes when loading a local file, where my existing code only has two (i.e., "file://C:/path"). Files used to load, but now they don't. I don't see what changed in 5.2.9 to cause that.

Ultimately, the question is why the main stylesheet loads but its <xsl:include>s do not, as they are in the same directory. Either they should both load or neither should load.

---
Another thing I noticed is that the up until PHP 5.2.9, libxslt was compiled against the same version of
libxml that was included with PHP. But starting with PHP 5.2.9,
libxslt was compiled against an older version of libxml than that
which was included with PHP. See below:

    5.2.5
    libxml Version => 2.6.26
    libxslt compiled against libxml Version => 2.6.26

    5.2.8

    libxml Version => 2.6.32
    libxslt compiled against libxml Version => 2.6.32

    === versions differ starting at 5.2.9 ===
    5.2.9
    libxml Version => 2.7.3
    libxslt compiled against libxml Version => 2.6.32

    5.2.16
    libxml Version => 2.7.7
    libxslt compiled against libxml Version => 2.6.32

It might be a mere coincidence that in 5.2.9 both my code stopped working and these versions differ, but it seemed worth noting.

Test script:
---------------
(based on XSL example at http://us.php.net/manual/en/xsl.examples-collection.php)

C:\xsltest\xsl.php
=====
<?php

$xml = new DOMDocument();
$xml->load('collection.xml');

$xsl = new DOMDocument();
$xsl->load('file://C:/xsltest/collection.xsl'); // <xsl:include>s fail
//$xsl->load('file:///C:/xsltest/collection.xsl'); // <xsl:include>s work

$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl);

echo $proc->transformToXML($xml);


=====
C:\xsltest\collection.xsl
=====
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 <xsl:include href="include.xsl"/>

 <xsl:param name="owner" select="'Nicolas Eliaszewicz'"/>
 <xsl:output method="html" encoding="iso-8859-1" indent="no"/>
 <xsl:template match="collection">
  Hey! Welcome to <xsl:value-of select="$owner"/>'s sweet CD collection! 
  <xsl:apply-templates/>
 </xsl:template>
</xsl:stylesheet>

=====
C:\xsltest\include.xsl
=====
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="cd">
  <h1><xsl:value-of select="title"/></h1>
  <h2>by <xsl:value-of select="artist"/> - <xsl:value-of select="year"/></h2>
  <hr />
 </xsl:template>
</xsl:stylesheet>

=====
C:\xsltest\collection.xml (same as on example page above)
=====
<?xml version="1.0"?>
<collection>
 <cd>
  <title>Fight for your mind</title>
  <artist>Ben Harper</artist>
  <year>1995</year>
 </cd>
 <cd>
  <title>Electric Ladyland</title>
  <artist>Jimi Hendrix</artist>
  <year>1997</year>
 </cd>
</collection>

Expected result:
----------------
include.xsl is loaded, and the script works, yielding:

  Hey! Welcome to Nicolas Eliaszewicz's sweet CD collection!

 <h1>Fight for your mind</h1><h2>by Ben Harper - 1995</h2><hr>
 <h1>Electric Ladyland</h1><h2>by Jimi Hendrix - 1997</h2><hr>

Actual result:
--------------
include.xsl is not loaded (despite the fact that collection.xsl is loaded), yielding these errors:

Warning: XSLTProcessor::importStylesheet(): I/O warning : failed to load external entity "file%3A/C%3A/xsltest/include.xsl" in C:\xsltest\xsl.php on line 11

Warning: XSLTProcessor::importStylesheet(): compilation error: file file%3A//C%3A/xsltest/collection.xsl line 3 element include in C:\xsltest\xsl.php on line 11

Warning: XSLTProcessor::importStylesheet(): xsl:include : unable to load file%3A/C%3A/xsltest/include.xsl in C:\xsltest\xsl.php on line 11



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-15 14:47 UTC] cataphract@php.net
PHP 5.2 is not supported anymore. Does this also affect PHP 5.3?
 [2011-02-15 21:02 UTC] clarkwise at gmail dot com
Yes, the same thing happens for all currently available versions of PHP 5.3 (5.3.0 - 5.3.5).

As a note, libxslt is compiled against libxml 2.6.32 in all PHP 5.3.x versions, while the bundled libxml is 2.7.x, as is the case with PHP 5.2.9 and greater.
 [2013-12-02 14:05 UTC] mike@php.net
-Assigned To: +Assigned To: ab
 [2013-12-02 14:05 UTC] mike@php.net
Cannot reproduce; Seems to be Windows issue.
 [2014-04-01 08:16 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3cb056f523d470a677a1c7fc186ce2720fece535
Log: Fixed bug #53965 &lt;xsl:include&gt; cannot find files w/ relative paths when loaded w/ &quot;file://&quot;
 [2014-04-01 08:16 UTC] ab@php.net
-Status: Assigned +Status: Closed
 [2014-04-03 08:02 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3cb056f523d470a677a1c7fc186ce2720fece535
Log: Fixed bug #53965 &lt;xsl:include&gt; cannot find files w/ relative paths when loaded w/ &quot;file://&quot;
 [2014-04-03 08:04 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3cb056f523d470a677a1c7fc186ce2720fece535
Log: Fixed bug #53965 &lt;xsl:include&gt; cannot find files w/ relative paths when loaded w/ &quot;file://&quot;
 [2014-04-10 04:47 UTC] tyrael@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3cb056f523d470a677a1c7fc186ce2720fece535
Log: Fixed bug #53965 &lt;xsl:include&gt; cannot find files w/ relative paths when loaded w/ &quot;file://&quot;
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 17 16:02:22 2014 UTC