Making <template> play nice with XML and tags-and-text

Inspired by a conversation with hsivonen in #whatwg, I spend some time
thinking about how we would design <template> for an XML world.  One idea I
had was to put the elements inside the template into a namespace other than
http://www.w3.org/1999/xhtml.  For example, consider the following XML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title of document</title>
</head>
<body>
Hello!
<template xmlns="http://www.w3.org/2012/xhtml-template">
  <script>
    alert("This script will not run because of its namespace");
  </script>
</template>
</body>
</html>

Unlike the existing "wormhole" <template> semantics, in this approach the
tags-and-text inside <template> would translate into DOM as usual for XML.
 We'd get the "inert" behavior for free because we'd avoid defining any
behavior for elements in the
http://www.w3.org/2012/xhtml-templatenamespace (just as no behavior is
defined today).

Whatever mechanism instantiates the templates would then
create corresponding elements in the
http://www.w3.org/1999/xhtmlnamespace, as usual.

Now that we have a working XML version of <template>, we can consider how
to port the element to HTML.  Fortunately, that's easy.  We just treat
<template> as triggering foreign content, analogous to how <svg> causes the
HTML parser to create elements in the http://www.w3.org/2000/svg namespace.

Adam

Received on Wednesday, 18 July 2012 16:20:47 UTC