The change from [set arg arg]
to
<tcl:set arg arg />
is easy, it can even be a compile time option (for the compiler not the scripts). However, representing the args as attributes might be a problem. The issue is the quoting rules for XML attributes conflicting with the quoting and other rules for Tcl args.
The model I am using is to allow the lexer find valid arg tokens and pass them to the parser to validate the grammer. Neither of these parts can verify the validity of the arguments (neither can the Tcl parser, arguments are opaque). I do examine the arguments a little. I verify they do not contain embeded commands, but combining two quoting schemes might confuse more than help the situation.
I looked into XSL, as others have pointed out, it is complex and unfriendly. It is also a full programming language, and could access resources based on what is contained in the XSLT. But the main issue is that it isn't apparent how the XML document would be created from the Tcl scripts, since the model with Tcl is to define variables and execute commands. You would still be stuck with the task of creating an XML document, or DOM from Tcl structures. My goal was to use the Tcl language as much as possible, and as safely as possible so that display code can be completely separated from other types of code. I also want to be able to use it in as many places as possible, like within a database or in procedures where templates might be stored in the database.
The webserver tclhttpd uses Safe-Tcl and a simple templating language. Files ending in .tml are run through subst
. Unfortunately this eliminates all the important selection and iteration commands that make a templating language useful.