Page 1 of 1

Problem parsing xslt file

Posted: Tue Aug 06, 2002 4:48 pm
by pavkb
Hi all,
The following is my xml file example1.xml

Code: Select all

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" href="example1.xsl"?> 
<person>
	<name>
		<firstname>John</firstname>
		<middlename>Michael</middlename>
		<lastname>Stevens</lastname>
	</name>
	<email>jstevens@company.com</email>
	<phone>
		<home>999 999-9999</home>
		<cellular>888 888-8888</cellular>
	</phone>
	<department>Software Engineering</department>
</person>
Following is the xslt file example1.xsl.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/person">
<html>
<head>
<title>XML and XSLT Example</title>
</head>
<body>
<table>
<tr>
<td>Personal Information:</td>
</tr>
<tr>
<td><xsl:value-of select="name/firstname" /></td>
<td><xsl:value-of select="name/middlename" /></td>
<td><xsl:value-of select="name/lastname" /></td>
</tr>
<tr>
<td>Email Address:</td>
<td><xsl:value-of select="email" /></td>
</tr>
<tr>
<td><xsl:value-of select="department" /></td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Together when loaded in IE 6.0 there are no errors.

Now here is the php code to do the transform.

Code: Select all

<?php 

    // Creating a XSLT Processor 
    // "$xsltproc" is the XSLT processor resource. 
    $xsltproc = xslt_create(); 

    // Processing the two files 
    $result = xslt_process( $xsltproc, 'example1.xml', 'example1.xsl' ); 

    // If we have a result then display the contents? 
    // If not then die and display the error information 
    if( $result ) &#123;     
            echo "$result"; 
    &#125; 
    else &#123;     
        die( sprintf( "The XSLT processor failed &#1111;%d]: %s", xslt_errno( $xsltproc ), xslt_error( $xsltproc ) ) ); 
    &#125; 

    // Free up the XSLT Processor 
    xslt_free( $xsltproc ); 

?>
All these files are located under XML directory of htdocs of apache.
Now when i load the above php file. I get the following
  • Warning: Sablotron error on line none: cannot open file 'C:/php/example1.xsl' in C:\Program Files\Apache Group\Apache2\htdocs\Myphp\XML\example1.php on line 8
    The XSLT processor failed [4]: cannot open file 'C:/php/example1.xsl'
Any suggestions why php is looking for the xsl file under php instead of where the php source file is :?:

Also, when i give the full path to the file in the php.

Code: Select all

// Processing the two files 
    $result = xslt_process( $xsltproc, 'C:\Program Files\Apache Group\Apache2\htdocs\example1.xml', 
'C:\Program Files\Apache Group\Apache2\htdocs\example1.xsl' );
i get the following in the browser
  • Warning: Sablotron error on line 1: XML parser error 4: not well-formed (invalid token) in C:\Program Files\Apache Group\Apache2\htdocs\Myphp\XML\example1.php on line 8
    The XSLT processor failed [2]: XML parser error 4: not well-formed (invalid token)
Now i looked at the php.ini file & put in the htdocs/xml dir location in includes entry.& in the doc_root entry.

Don't know what else to do.

I have my xslt module enabled.

Thanks for help
Pavan

Posted: Tue Aug 06, 2002 5:10 pm
by volka
the absolute path has wrong file/direcotry-seperators.
try something like

Code: Select all

$cwd = substr($_SERVER&#1111;'SCRIPT_FILENAME'], 0, strrpos($_SERVER&#1111;'SCRIPT_FILENAME'], '/')+1);
$result = xslt_process( $xsltproc, $cwd.'example1.xml', $cwd.'example1.xsl' );