I'm intrigued. You might have noticed that I like Lisp. Itellectually, that is. I don't really speak it. I finally decided to dive and try and learn it. On the surface it is not that hard - the language is extremely simple, essentially it has brackets and white space as separators, a couple of special forms - something like built in functions or language constructs in other language terminology, and a few really cool features like quote, unquote, quasiquote, (precious special forms actually), oh, yes, it has an eval.
In order to go forward with the learning I shall try and implement a simple web-design friendly template for xml applications. The idea is similar to TAL, or taglibs, etc...
A template is a valid xml document with namespaces. Some, not all, namespaces have programmatic meaning, that is they should be interpreted by an application. A template engine should be able to read an xml document and execute those statements encoded in xml.
an XML source fragment
<cms:node-content>
<div>
<cms:node-title>
<h3><a cms:node-title-link="relative" >
<cms:node-title-text >
Sed ut perspiciatis unde omnis iste natus error sit
voluptatem accusantium doloremque laudantium, totam
rem aperiam, eaque ipsa quae ab illo inventore veri-
tatis et quasi architecto beatae vitae dicta sunt
explicabo.
</cms:node-title-text >
</a>
</h3>
.....
</div>
</cms:node-content>
This should execute cms:node-content, cms:node-title, cms:node-title-link and cms-node-title-text, which in turn perform some action. Each of the cms:* functions should know the xml context from which they are called. They might transform the underlying xml or be completely silent, being used for their side-effects.
A first draft of a scheme representation
(div
(cms:node-title
(h3
(a (cms:node-title-text Sed ut perspiciatis...)
(@ (cms:node-title-link "relative")
)
)
)
)In the above code I presume that all namespace tags have corresponding scheme functions defined. This code is a rough, simplified approximation of SXML produced s-expressions. The key is that the s-expressions should be evaluateable scheme constructs. This code might evaluate to:
<div class="node-content>
<h3><a href="Cicero/-45/de_Finibus_Bonorum_et_Malorum"
title="Cicero, de Finibus Bonorum et Malorum">
Section 1.10.32 of "de Finibus Bonorum et Malorum",
written by Cicero in 45 BC</a>
</h3>
.....
</div>The source XML fragment for all practical purposes defines a template. The idea is that a web-designer will provide a solid xhtml design, possibly with the added markup. The html file is an example rendering of that particular page, which can be filled in by a server side software. This approach is a useful double sword - designer friendly and enables programming by example, i.e a collection (union) of example renderings with the appropriate add-on markup, can be joined into a more complex, context dependent template.
The above should describe what forms are needed for a decent template system.
Well, I need to dig deep and try and produce a solution, which does somethin g like this. I'll give myself a bonus point for making it simple. Another bonus point for me would be for a slim solution, this bonus point will be awarded only if the solution is readable.