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>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>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 ) {
echo "$result";
}
else {
die( sprintf( "The XSLT processor failed ї%d]: %s", xslt_errno( $xsltproc ), xslt_error( $xsltproc ) ) );
}
// Free up the XSLT Processor
xslt_free( $xsltproc );
?>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'
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' );- 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)
Don't know what else to do.
I have my xslt module enabled.
Thanks for help
Pavan