HTML templates and XML

Part of Data

Author(s) and publish date

Published:
Skip to 5 comments

There's been some discussion recently about a new HTMl facility that provides reusable content: stuff that can appear in a Web page multiple times. It’s a facility similar to XInclude in some ways, except more limited in scope.

The template element is treated specially by the parser in a Web browser when it creates a DOM tree: it’s hidden and not part of the regular DOM. This means that normal DOM JavaScript methods won’t find the content if they traverse the tree, getElementsByID won’t find elements in templates, and so on.

Similarly, if you use XPath or XSLT in the browser, the template element’s contents will be invisible.

The question was asked, is this OK for XML?

The answer, of course, is yes, it’s perfectly fine. The application can construct a data model from XML in any way it likes. XPath and XSLT in the browser operate on the DOM tree, so if something isn’t in the DOm they won’t see it.

Outside of a Web browser, template is just a normal element and XML systems have no reason to treat it specially. This is actually what you need, so that you can search for templates on your Web server.

Related RSS feed

Comments (5)

Comments for this post are closed.