I've got an idea. Instead of using XML, which is incredily slow to parse and create, we could just use standard Perl data structures. We'll call them objects. Then we'll need a text language for writing the description of how to connect them. We'll call that Perl.
This is exactly why Mark-Jason Dominus wrote Text::Template and it is exactly why it is paradoxical that you would be such a Template Toolkit fiend when it is in fact a 3rd technology between two technologies which can stand quite well on their own two feet (HTML and Perl). As MJD said: "the second you start writing your own language, you realize you need a loop. And then a reference. And pretty soon you realize you need Perl.. and you already know it.. so why not use it! (paraphrase).
It's trivial to do code generation in Perl with the power of eval(), so why create an entirely new way to do it?
Perl is a
verysyntax-heavy and syntax-complicated language. Now it makes for easy English-like hand-coding, but for program text generation, Prolog and Lisp are the easiest because they have 50-100 times fewer syntactic elements and 100 to 1000 times fewer funny ambiguous overloaded operators and statements. Exageration intentional, but not far off the mark.