I'm trying to rebuild from scratch my CMS, Fluorine CMS. And in this process, I have to code some template engine. I thought I could do it using XML. Here's a functional schema:

Fluorine CMS template engine functional schema

Basically, you got to read the schema from right to left ;) Keep in mind that "XHTML output" is just to make the schema smaller, because it'll be used to generate RSS feeds / export, RDF metadata, maybe some DocBook output... well, anything in XML.

There are two big kind of interaction between Fluorine and its Template Engine: namespaces and contexts.

If you're coding a plugin that, let's say, outputs "hello world" in the generated XML, you register a namespace ("hello" bound to "http://www.example.org/", eg), and you can use <hello:xxx>. "xxx" can be any XML-valid name (ie nearly anything). It's you the one who handles all the freaky "behind the scene" stuff in your plugin. You just need to register a namespace to make the Template Engine aware of your existence, and follow a very simple API: declare a static handler() func in your class (with some args).

My little baby sister can do it with ease
It's easier than learning your ABCs...

Kylie Minogue, Loco-Motion

But if you want to output some more complex stuff, using a template (eg in a menu), you need to register a context. It's more or less the same thing than registering a namespace, but it only tells Fluorine CMS to pass you everything it encounters in <caf2:template for="urn:...">. The URN is the one you registered, caf2 is Fluorine's default namespace name.

My problems comes from here: if you want to make a plugin, you have to build an internal XML tree in order to repeat it as many times as you need! Not that easy, heh? I chose to use SAX, because it fits the "line-per-line" (or linear) parsing of the template file (pure XML, using XInclude and stuff) I need... but maybe I should use DOM? Using both would be a little crazy, as it's rare to encounter both on a server... What do you think of that?