The Template Factor
XUL has one further trick up its sleeve: the <template> tag and its subsidiary tags. The <template> tag allows an XUL document's content to be determined in a data-driven way. In HTML or XHTML, this can only be done by server-side generation of the document, or by rather messy Dynamic HTML techniques. In XUL, the <template> tag allows a piece of XUL content to be repeated uniquely for each data item that matches the template. In the Mozilla browser, for example, the bookmarks displayed on the Personal Toolbar are generated by a single XUL template. If more bookmarks are added, more items appear on that toolbar.
This templating system is rather like a simple report-writing language, but with one difference: The generated content can change dynamically. If a bookmark disappears, the content that was generated to represent it disappears as well. This makes the template system somewhat automated, and it can adjust due to user input or information received from other sources, such as from across the Internet.
This dynamic behavior is a whole level more sophisticated than modern web page display. A modern browser displays whatever bits it has of a loading web page, before the page is completely delivered. We're now accustomed to seeing missing chunks of a page fill in after the content that surrounds them is in place, especially if that missing chunk is an image. In that case, all is quiet once the web page is fully loaded. With a XUL template, however, the page might change even after its document is fully loaded. This is the template at work. In ordinary HTML, this can only be done using bolted-on Dynamic HTML. In XUL, the <template> tag is a fundamental part of the XUL language.