Uriptical Posted September 20, 2006 Share Posted September 20, 2006 Hi, I'm thinking up ideas for a CMS that I'm planning to build. One of the features I want to implement is a templating system, so that if in the future a designer with no experience of PHP wants to change the HTML and CSS of the page, he or she can do with relative ease.The solution I have in mind is to create a bunch of XSL templates that the designer would be able to modify without touching any PHP code. PHP would get the appropriate data from the database, generate the XML based on this data, and then display it as XHTML, using something like this code (taken from the php manual):[code]<?php// Load the XML source$xml = new DOMDocument;$xml->load('collection.xml');$xsl = new DOMDocument;$xsl->load('collection.xsl');// Configure the transformer$proc = new XSLTProcessor;$proc->importStyleSheet($xsl); // attach the xsl rulesecho $proc->transformToXML($xml);?> [/code]However, some of the information in my CMS will most likely be private, so I'm wondering if perhaps this isn't the best method to use, as the XML wouldn't be able to be saved on to the web server. Also, would it significantly slower converting it to XML first, and then to XHTML, especially since I don't really *need* the XML on it's own for anything.Is this a good way of creating a templating system or not? Or would it be better to write my own templating engine from the ground up? Quote Link to comment https://forums.phpfreaks.com/topic/21362-creating-templates-with-xsl/ Share on other sites More sharing options...
mrfritz379 Posted September 22, 2006 Share Posted September 22, 2006 The framework that I posted about yesterday ([url=http://phritz.fritz-works.com]Phritz[/url]) actually uses XSL templates for all of its output. You're right that it is a little slower than using a system such as Smarty, but I think that the benefits outweight the slight performance hit. The solution I used to help out with that was to avoid using the DOM implementations for the creation of the XML string. The assign() method works just like Smarty, creating indeces in an associative array instead of using $dom->createElement, which is way slower. Once you get to fetch() or display(), the XML string is created by traversing the array and manually building an XML document which is passed to the XSL processor and only then converted to a DOM object to be processed. When I benchmarked it against Smarty it was only behind a couple 1/1000 of a second, though that was on relatively simple page. On a more complex page rendering (say if you are processing a large number of templates for side blocks or something) it would probably show a bigger performance hit. Feel free to download the source of Phritz and look at the template engine. Its GPL, so you can modify it and use it for your own if you like it. Quote Link to comment https://forums.phpfreaks.com/topic/21362-creating-templates-with-xsl/#findComment-96700 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.