A few weeks ago, someone was asking some questions about XUL templates. In the process of answering, I had a revelation and finally understood completely how templates work. I also decided it was finally time to try to understand the template building code. This code is rather complicated, involving about 20 - 30 different data structures. I still don't understand what all of them are for, and I don't think it's possible that anyone ever will. I think the complexity comes from the code needing to be scalable for templates with lots of rules and conditions, and ensuring that only the necessary parts need to be reevaluated. Most templates only have a few consitions so I'm not convinced that the complexity is worth it. But then again, I wouldn't be able to tell for sure without ripping it all out and changing it, which I don't think I want to do.
I am, however, more sure that the template builder actually does work as it's supposed to. Any problems people have are caused by errors either in RDF or template syntax. Common problems include using the wrong RDF content type, using the different parts of the RDF triple incorrectly, or putting the wrong values or variables in the template itself.
That said, I'm in the process of creating some patches for the template builder, one patch to print template syntax errors to the JS console, and another nice patch for the enhancement bug 86435.