php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #14965 Sablotron XLST encoding error
Submitted: 2002-01-10 08:35 UTC Modified: 2002-11-26 15:17 UTC
Votes:15
Avg. Score:4.3 ± 0.9
Reproduced:15 of 15 (100.0%)
Same Version:6 (40.0%)
Same OS:10 (66.7%)
From: andrew dot stopford at btinternet dot com Assigned: k.schroeder (profile)
Status: Closed Package: Documentation problem
PHP Version: 4.1.1 OS: Windows 2000
Private report: No CVE-ID: None
 [2002-01-10 08:35 UTC] andrew dot stopford at btinternet dot com
Dear Sirs,

I have come across an issue with the Sablotron XSLT extension. The issue is similar to the issue reported to http://bugs.php.net/bug.php?id=14499 however my encoding has been set.

Using Windows 2000 Server SP 2, PHP 4.1.1 and IIS 5.0 I tested the following code.

XML

<?xml version="1.0" encoding="UTF-8"?>
<PEOPLE>
	<PERSON>
		<NAME>Andrew</NAME>
	</PERSON>
</PEOPLE>

XSL

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/">
		<html>
			<head/>
			<body>
				<xsl:apply-templates/>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="NAME">
		<span style="display:list-item; font-family:Arial">
			<span style="display:list-item; font-family:Arial">
				<xsl:apply-templates/>
			</span>
		</span>
	</xsl:template>
</xsl:stylesheet>

PHP

<?

//path
$file_path = "http://localhost/";

//xml file
$xml_file = $file_path . "people.xml";

//xsl file
$xsl_file = $file_path . "people.xslt";

// Allocate a new XSLT processor
$xh = xslt_create();

// Process the document
$result = xslt_process($xh, $xml_file, $xsl_file);

xslt_free($xh);

?>

From this script the following error is returned:

Warning: Sablotron error on line 1: unknown encoding '' in c:\stuff\xlst_transform.php on line 18

line 18 is the following

$result = xslt_process($xh, $xml_file, $xsl_file);

The following adapation of the XSL file also gives the same result.

<?xml version="1.0"?>
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="NAME">
            <span style="display:list-item; font-family:Arial">
                <xsl:apply-templates/>
            </span>
    </xsl:template>
</xsl:stylesheet>

I also tested the code using Apache 1.3.22 under Windows 2000 server with the same result.

Andrew Stopford


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-10 11:21 UTC] hholzgra@php.net
are you sure the filenames you passed are correct?

i got the same message yesterday and the reason
was an empty stylesheet due to a missing global
declaration
(i was using variables instead of files but it
 looks like the same problem -> nonexistant 
 xslt input)
 [2002-01-10 12:02 UTC] msopacua at idg dot nl
You set the path as an http:// url.
By default, Sablotron doesn't provide an http handler, nor does the current xslt extension.

This also applies to external entities and dtd's. Use the arg:/_xml syntax and fetch the url's first (fopen or even better with the curl extension)

=> Should be documentation problem as the file open method is not specified and could be interpreted as the php fopen.
 [2002-01-10 14:14 UTC] andrew dot stopford at btinternet dot com
Hi,

I tried the following code.

<?php

//path
$file_path = "http://localhost/test/";

//xml file
$xml_file = $file_path . "people.xml";

//xsl file
$xsl_file = $file_path . "people.xslt";

//open xml file
$xmlfile = fopen ($xml_file, "r");
while (!feof ($xmlfile)) {
    $xml_file_contents = fgets($xmlfile, 4096);
    //echo $xml_file_contents;
}
fclose ($xmlfile);

//open xslt contents 
$xslfile = fopen ($xsl_file, "r");
while (!feof ($xslfile)) {
    $xsl_file_contents = fgets($xslfile, 4096);
    //echo $xsl_file_contents;
}
fclose ($xslfile);

$arguments = array(
     '/_xml' => $xml_file_contents,
     '/_xsl' => $xsl_file_contents
);

// Allocate a new XSLT processor
$xh = xslt_create();

// Process the document
$result = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments); 

xslt_free($xh);

?>

The paths are correct as both files are displayed. Still the same error message. Changed the XML file to use a local file path for the DTD with no effect.

Andrew
 [2002-01-10 14:21 UTC] hholzgra@php.net
your problem is

  $file_path = "http://localhost/test/";

change it to

  $file_path = "$DOCUMENT_ROOT/test/";

sablot will read from local filesystem only,
while within the XML it's safe to have URLs
as pathes
 [2002-01-10 14:21 UTC] hholzgra@php.net
moved to "Documentation problem"

 [2002-01-10 14:35 UTC] andrew dot stopford at btinternet dot com
Hi,

$DOCUMENT_ROOT is a blank variable

also trying the file path rather than HTTP e.g.

$file_path = "C://test//";

Produces the same error.

All paths are correct

Andrew
 [2002-01-10 14:40 UTC] andrew dot stopford at btinternet dot com
slight correction to my last message it should read

$file_path = "C:\\test\\";

:)

Andrew

 [2002-01-14 07:32 UTC] f dot vulto at re-base dot com
On Windows 98, Apache 1.3.22, PHP 4.1.1, Sablotron 0.71, I experienced the same problem with 'xslt_process()', which I was able to solve using the 'file://' specifier:

   $result = xslt_process($xh,
      'file://E:/Web/test.xml',
      'file://E:/Web/test.xsl');

Strange enough, since the command:

   $result = xslt_process($xh, 'test.xml', 'test.xsl');

runs just fine on FreeBSD 4.4, Apache 1.3.22, PHP 4.1.1, Sablotron 0.71.  On Windows however, the above command gives me error code 4:

   cannot open file 'd:/programs/apache/test.xsl'
   
because Sablotron is looking for the xsl file in the Apache program directory.  After specifying the full file name for the xsl file:

   $result = xslt_process($xh, 'test.xml',
      'E:/Web/test.xsl');

I receive error code 63:

   unknown encoding ''

After using the 'file://' prefix for the xsl file and a full file name for the xml file, I receive error code 2:

   XML parser error 9: junk after document element

Only when using the 'file://' prefix for both the xsml and xsl file, xslt_process() seems to work fine for Windows:

   $result = xslt_process($xh,
      'file://E:/Web/test.xml',
      'file://E:/Web/test.xsl');

See also:

   http://archive.gingerall.cz/archives/sablot/msg01858.html


HTH, Freddy Vulto
 [2002-01-14 08:21 UTC] andrew dot stopford at btinternet dot com
Hi,

I can confrim Feddy's code works fine on Windows 2000 (thanks Freddy :), however the code I submitted earlier still produces the error so using either file or HTTP with fopen and using the array arguments of xslt_process function still produces the error.

Andrew
 [2002-01-14 13:17 UTC] msopacua at idg dot nl
Unless the below is a typo, it's quite logical:
while (!feof ($xmlfile)) {
    $xml_file_contents = fgets($xmlfile, 4096);
    //echo $xml_file_contents;
}

should read:
while (!feof ($xmlfile)) {
    /notice the dot
    $xml_file_contents .= fgets($xmlfile, 4096);
    //echo $xml_file_contents;
}
Unless you have an xmlfile, consisting of 1 line, smaller that 4096 bytes, $xml_file_contents, will consist of the last line only.
 [2002-01-18 17:25 UTC] nigelswinson at users dot sourceforge dot net
Hi folks (please be gentle, my first post to bugs.php.net).

I've got exactly the same mayhem happening on my machine too.  Running with Apache 1.3.22, and php as a cgi binary.

Here's the example code, commented, shows all that I've found this evening.  Basically the only way I can get xslt_process() to work is using the arguments array, putting file names in with getcwd(), file://, include path just doesn't work :o(

<?

error_reporting (E_ALL);

// My include path is 
// include_path = ".;E:\Webserver\public_html"
//
// PHP is installed to D:\Program Files\Php

$xmlFile="Php.XPathDocumentation.xml"; 
$xslFile="Php.XPathDocumentation.xsl"; 

echo '<hr>Read file<br>';

// Get the contents of the files, 
// Both calls work ok.
$xslData = implode('',file($xslFile));
$xmlData = implode('',file($xmlFile));

echo '<hr>Create parser<br>';

$hXslt = xslt_create();

echo '<hr>Process with filenames (no path)<br>';

// This gives me a error:
// Warning: Sablotron error on line none: cannot open file 
// 'd:/program files/php/Php.XPathDocumentation.xml' 
// in e:\cvs\php.xpath\xpath-develop\doc\Php.XPathDocumentation.php on line 79
// $result contains nothing
$result = xslt_process($hXslt, $xslFile, $xmlFile);
echo $result;

echo '<hr>Get current working directory<br>';

// This returns e:\cvs\php.xpath\xpath-develop\doc
echo getcwd();

echo '<hr>Use getcwd() and with filenames (no path)<br>';

// Warning: Sablotron error on line 1: unknown encoding '' in 
// e:\cvs\php.xpath\xpath-develop\doc\Php.XPathDocumentation.php on line 82
// $result contains nothing
$result = xslt_process($hXslt, getcwd().'\\'.$xslFile, getcwd().'\\'.$xmlFile);
echo $result;

echo '<hr>Use file:// getcwd and with filenames (no path)<br>';

// This call succeeds with no error.
// $result contains the entire xml file unprocessed (whitespace trimmed).
$result = xslt_process($hXslt, 'file://'.getcwd().'/'.$xslFile, 'file://'.getcwd().'/'.$xmlFile);
echo $result;

echo '<hr>Use the xml and xsl as arguments<br>';

// But this works fine and produces the transformation as I expect
$arguments = array(
     '/_xml' => $xmlData,
     '/_xsl' => $xslData
);
$result = xslt_process($hXslt, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments);

if ($result) {
    echo $result;
} else {
    echo "There was an error that occurred in the XSL transformation...\n";
    echo "\tError number: " . xslt_errno() . "\n";
    echo "\tError string: " . xslt_error() . "\n";
    exit;
}

echo '<hr>';

xslt_free($hXslt);

?>

If you want any copies of the files that I've been using, drop me a mail.  I feel fairly confident that these bugs occur regardless of the xml and xsl file, given that the final version produces exactly the expected transformed output. 

Nigel
 [2002-04-26 05:23 UTC] khalid_kary at hotmail dot com
Hi, the same problem here on PWS on winodws ME, the code is 
<?php
//create processor
$my_xslt=xslt_create();
//output the processing result
echo xslt_process($my_xslt,getcwd()."//cd_catalog.xml",getcwd()."\\cd_catalog.xsl");
//free the processor
xslt_free($my_xslt);
?>
returned
Warning: sablotron error on line 1, unknown encoding...

using this code the problem was completely solved...

<?php
//create the processor
$my_xslt=xslt_create();

//process the fiel and echo the result
echo xslt_process($my_xslt,"file://".getcwd()."//cd_catalog.xml","file://".getcwd()."\\cd_catalog.xsl");

//free the processor
xslt_free($my_xslt);
?>
thank u,
 [2002-05-02 00:55 UTC] tim at zero-interactive dot com
To get this to work under Win2K and PHP 4.2.0, you must put have "file://" prefixed to every parameter that requires a file.  This includes the xml, xsl and the output files.

This does NOT however require to upgrade you php_xslt dll to the version suggested by the person in bug 14499.
 [2002-05-27 21:19 UTC] webmaster at celticbride dot com
Using the xslt_set_base() function on Win2k can provide a cleaner solution to this platform's limitations with Sablotron:

$xh = xslt_create();
xslt_set_base($xh, 'file://' . $DOCUMENT_ROOT . '/examples/');

Note the trailing slash in the above line.

The following line would then work on Win2k:

$result = xslt_process($xh, 'example.xml', 'example.xsl');
 [2002-10-19 00:40 UTC] dbritton at sc dot rr dot com
Using the xslt_set_base() function as suggested in the May 27 posting gets around the problem on Win98, too.
 [2002-11-26 15:17 UTC] k.schroeder@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 04:01:27 2024 UTC