XSLT server side parsing in PHP

I know my way around in XML and XSLT, and have made some pages that work properly in Firefox and IE6. Now what I would like to do is parse those files on the server using PHP. I've found something that looks as a start, but is not complete and not correct.

$html = xslt_process$xsltproc, 'index.xml', 'album.xsl');

I found this here on EE, and I suppose it should be something like this: take an xml-file and an xsl-file, and process it. I'm not a PHP-programmer, so would like some help here. I see the opening brace is missing. I suppose the $html string should be displayed, and that's it?
LVL 1
grexxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

grexxAuthor Commented:
Well, I just found this example:

<?php

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

// Process the document
if (xslt_process($xh, 'index.xml', 'album.xsl', 'result.xml')) {
   echo "SUCCESS, sample.xml was transformed by sample.xsl into result.xml";
   echo ", result.xml has the following contents\n<br />\n";
   echo "<pre>\n";
   readfile('result.xml');
   echo "</pre>\n";
} else {
   echo "Sorry, sample.xml could not be transformed by sample.xsl into";
   echo "  result.xml the reason is that " . xslt_error($xh) . " and the ";
   echo "error code is " . xslt_errno($xh);
}

xslt_free($xh);

?>

When I run it, I get the following error:

Fatal error: Call to undefined function: xslt_create() in /var/www/html/album/040915/catalunya/album.php on line 4

What't the problem here?
0
dualsoulCommented:
You need to instal Sablotron - XSLT processor, you can use with PHP.

this links should give you info for download, install, and some samples:

http://www.gingerall.com/charlie/ga/xml/x_sabphp.xml?s=org
http://genomenews.free.fr/tutorials/sablot.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
grexxAuthor Commented:
If I look at PHPInfo, then I see this at DOMXML

DOM/XML       enabled
DOM/XML API Version       20020815
libxml Version       20606
HTML Support       enabled
XPath Support       enabled
XPointer Support       enabled
DOM/XSLT       enabled
libxslt Version       1.0.33
libxslt compiled against libxml Version       2.5.11
DOM/EXSLT       enabled
libexslt Version       1.0.33

This looks like XSLT should be supported. Or is this separate from Sablotron?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

dualsoulCommented:
hm...i see libxml and libxslt, but don't see Sablotron...

why not to try install it and run some samples?
0
grexxAuthor Commented:
It's not my server, it's the server of my isp, and they say DOMXML is installed as parser (so Sablotron is not needed in their view). See for more info:

http://nl3.php.net/manual/en/ref.domxml.php and
http://nl3.php.net/manual/en/function.domxsltstylesheet-process.php
from which the following example:

<?php
$document = new DOMDocument('index.xml');
// Unfortunately there's no such method for DomXsltStylesheet
$stylesheet = domxml_xslt_stylesheet_file('/path/to/stylesheet');
$params = array(
   'param1' => 'value1'
   ...
   , 'paramN' => 'valueN' );
$result = $stylesheet->process($document, $params);
?>

This example doesn't work. I don't know what to use for the parameters ($params), so I deleted that and removed it from the $result line.  The error I get is about line 2 ($document):

Warning: domdocument(): Entity: line 1: in /var/www/html/album/040915/catalunya/album.php on line 2

QUESTIONS
1) Can I do without Sablotron and does DOMXML replace the need for it?
2) If DOMXML is enough to get a parser working, what's wrong with the above example?
3) What should I do with the parameters?

I've added a few points.
0
grexxAuthor Commented:
Well I see I haven't copied the example really well. So here it is again, how I used it. The files index.xml and album.xsl are in the same directory as the parser-php-file. Using absolute paths doesn't solve anything.

<?php
$document = new DOMDocument('index.xml');
// Unfortunately there's no such method for DomXsltStylesheet
$stylesheet = domxml_xslt_stylesheet_file('album.xsl');

$result = $stylesheet->process($document);
?>
0
grexxAuthor Commented:
I still don't know where I stand. So I repeat my questions:

QUESTIONS
1) Can I do without Sablotron and does DOMXML replace the need for it?
2) If DOMXML is enough to get a parser working, what's wrong with the above example?
3) What should I do with the parameters?

And I've added some point....
0
grexxAuthor Commented:
<?php
//Transformer XML -> HTML par XSL
$CurrentDir = dirname(__FILE__);
$xmldoc = domxml_open_file("$CurrentDir\\sample.xml");
$xsldoc = domxml_xslt_stylesheet_file("$CurrentDir\\sample.xsl");
$result =  $xsldoc->process($xmldoc);
print $xsldoc->result_dump_mem($result);
?>

This code just solved my problem. It works, and I don't need Sablotron for now. Maybe Sablotron has more or better support for XSLT, but for now I can do what I need to do.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.