|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 11:00:01 2025 UTC |
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 VultoUnless 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.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