Transform your PHP with XSLT

This is an article discussion thread for discussing the SitePoint article, “Transform your PHP with XSLT

Interesting article.

Now I am really glad I’ve being using XML/XSLT extensivelly on my ASP.NET.

That means I could port my websites to Apache/PHP with minimal fuss.

Or maybe not … just realized! I use MS SQL Stored Procedures extensivelly too - and that can’t be ported to MySQL without a lot of fuss.

I take it PHP doesn’t support that?

Very very useful article, and the best part is the example works!! Thanks!

I tried this and got salbotron, etc installed - but firstly – it keeps referring to c:\php\docbook.php – how do I change this to see my 127.0.0.1 automatically?

Secondly, I hardcoded the path to see what would happen and I get this error;

XSLT processing error: XML parser error 4: not well-formed (invalid token)

On php.net it says the files have to be saved as UTF-8, which I’ve done – but it still comes up with the errors.

How do I fix these two issues?

I looked on the net and found that sniptools has a range of salbotron xslt+xml examples which work perfectly and I was able to adapt one of the more “simplier” demos to make this code work properly.

Sniptools website:


<?php
# Adapted docbook.php

// Xml and XSL files
$xml_file = "docbook.xml";
$xsl_file = "docbook.xsl";

// Allocate a new XSLT processor
$xh = xslt_create();
$fileBase = 'file://' . getcwd () . '/';
xslt_set_base ( $xh, $fileBase );

// Process the document
$result = xslt_process($xh, $xml_file, $xsl_file);
if (!$result) {
    // Something croaked. Show the error
    echo 'XSLT processing error: ' .xslt_error($xh) ;
}
else {
    // Output the resulting HTML
    echo $result;
}

// Destroy the XSLT processor
xslt_free($xh);

?>

Sadly, this code is a little redundant for php5 (or it was in my case anyway):

See //http://www.php.net/manual/ref.xsl.php particularly //http://www.php.net/manual/ref.xsl.php#45415

What i don’t understand is how is this better then a “normal” template engine, this is allot more confusing creating a new template because of all the extra tags.

Also what is the advantage of storing articles in xml, will a database not have faster performance then a xml doc, this would get really large at some point right?

Could somebody explain to me the real advantages for xml and xlst? Apart from RSS feeds?

I think the advantage is that you can also push this rendering out to the client, enabling rich web apps like gmail without the fuss of writing two templates(one for the server to render, and another for the client to render)

Hello, I tried to follow the installation but I got an error while trying the code in page 3 !

Seems that I lack of php_xslt.dll, where to find it ? I have downloaded expat and sablotron, and searched for php_xslt.dll, but can’t find any !

Thanks !

I have to find out the hard way but it should be noted that “php_xslt.dll” is only included in php 4 versions and lower it is not included or supported in php5 or higher.

i cant find sablotron anyone knows where i can find this?