I work with a lot of Content Management Systems, and one large problem is that 90% of the websites built with them look like each other. I believe this has to do with the difficulties in editing a module, component, plugin or extension’s output HTML code. This could be resolved with the use of XSLT, and we would also gain some nice side effects from doing so.
What is XSLT? Well, in short, you take an XML document and template it out with a XSL file. Then we run these two files through PHP5 and the viewer sees only HTML code. Here’s an example:
XML File:
<xml>
<para>Hi There</para>
</xml>
XSL File:
<xsl:template match="para">
<div class="hi"><p>
<xsl:apply-templaes/>
</p></div>
</xsl:template>
PHP5 File:
$doc = new DOMDocument();
$doc->load('cached_filename.xml');$xsl = new DomDocument();
$xsl->load("filename.xsl");
$proc = new XsltProcessor();
$proc->registerPhpFunctions();
$xsl = $proc->importStylesheet($xsl);
print $proc->transformToXML($doc);
Output html code:
<div class="hi"><p>Hi There</p></div>
So, how would this look? Let’s use Joomla! as an example. Every single module and component will come with a .php file and a .xsl file. The .php file will create a new cache of the .xml file required, if the xml does not exist or is unchanged. In some cases, the cache will need to be disabled. The cache filenames are saved to the database. The .XSL file will be saved to a special folder, allowing the developer to edit both the output XML and the XSL file used to template out the information.
In most cases, developers will only need to modify the XSL file, meaning that there is no need to modify any PHP code. This also means that we will have much more control over the output code, even when using 3rd party extensions or messy code, and completely divides the output from the actual code.
The problem would be moving everyone over to using the XSL / Xpath / Xpointer method of templating XML files into HTML. I don’t think learning is that big of an issue, however, because after you understand this stuff you will realize that it is easier to template out XML than it is to code raw HTML. For one, you know everything has a template, all your div’s get closed! Your design is just easier to maintain XHTML standards and not break.
Also, with all these cached XML files we can easily string them together to create our RSS feed, and I am cure it would be easy to let the developer choose which files are included.
Do I have any support with this idea? Please comment.