1 users online. Create an account or sign in to join them.Users

Search

Recently I've been working on a site that lets members register and add their own content and choose themes -- sort of like MySpace, only not as crap. We faced some issues along the way with theming, mainly that all themes had to work from the same markup. This means that themes are all very similar to each other.

Over the past few weeks I've been thinking on how we can avoid this sort of issue, my idea is this: As normal you generate a HTML page, but instead of outputting it, you capture the data into a variable:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template name="/">
        <xsl:variable name="html">
            <xsl:apply-templates select="data" />
        </xsl:variable>
    </xsl:template>
</xsl:stylesheet>

Next you use the EXSLT node-set function (http://www.exslt.org/exsl/functions/node-set/index.html) which takes the HTML variable and lets you transform it once again:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template name="/">
        <xsl:variable name="html">
            <xsl:apply-templates select="data" />
        </xsl:variable>
        <xsl:variable
            xmlns:exslt="http://exslt.org/common"
            name="html-nodes" select="exslt:node-set($html)"
        />

        <!-- Logic to include a theme stylesheet -->

        <xsl:apply-templates select="$html-nodes" mode="theme" />
    </xsl:template>
</xsl:stylesheet>

By doing this you could apply a theme of your choice and alter the output based on the requirements for that theme. As you can probably guess, I'm not sure how to include a theme XSLT file, I don't think it's possible to include within a template.

Still, let me know what you think...

This is a very cool and abstract method and I think there's a couple of projects on our end that would greatly benefit from this. Thanks for sharing!

How are you guys implementing themes after all? Using @buzzomatic's method above? Or are you following other approaches?

Thanks for tips!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.2 or above
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.0 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details