SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    PHP Guru's Avatar
    Join Date
    Jan 2009
    0 Post(s)
    0 Thread(s)

    XSLT as template engine for php?

    There are so many templating engines like smarty, flexy, phptal, Html_Template_Sigma to name a few. More of them have some php code inside the template. Only the Html_Template_Sigma seems to implement a complete separation of html and php code.

    Some are faster than others. usually if the ones that require some type of php code or loops inside the template are the faster ones, so the speed of template engine comes are a cost of being less separated from html, meaning a non-programmer may have harder time editing such templates.

    This brings the question: are anyone in this forum using the XSLT templates as a templating engine? The XSLT is not a simple template to master, certainly not easy for non-programmer to edit or even understand.

    But it seems to me that there would be some benefits to using it - php supports in with built-in xsl extension, it's a standard, meaning you can always find an expert to design a template for you.

    All that is required is that your script outputs an xml instead of the html, then xsl processor loads your xml + your xslt template and spits out a well-formatted html.

    And creating xml string from data in database if easy, you can use DOM, SimpleXML, or even sql2xml class from pear.

    The only question still remains for me - how fast or how slow is the XSL processor comparing to using Smarty templates for example?

    Has anyone researched this topic or actually using XSLT templates as the site's template engine?

  2. #2
    SitePoint Zealot cholmon's Avatar
    Join Date
    Mar 2004
    0 Post(s)
    0 Thread(s)
    Quote Originally Posted by View Post
    Has anyone researched this topic or actually using XSLT templates as the site's template engine?
    I took this approach a few years ago, right around the time PHP5 first came out. At first I found that a simple XSL stylesheet would get processed very quickly, but as I began producing larger HTML output I became less impressed, especially when building complex, dynamic layouts. I eventually came back around to just using pure PHP templates for simplicity's sake, and so that they'd get opcode-cached via APC. In the end, I find pure PHP to be the easiest thing to maintain, not only for myself, but also (particularly) when handing code off to other developers.

    Knowing and using XSLT is one thing. Writing it all in a well organized, maintainable manner that won't make other developers want to quit is a rare skill indeed.
    Drew C King: PHP Developer
    <?= $short_tags++ ?>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts