code: function getOrCreateTemplateContentsOwner(template) {
      var doc = template.ownerDocument
      if (!doc.defaultView)
        return doc;
      var d = doc.templateContentsOwner_;
      if (!d) {
        // TODO(arv): This should either be a Document or HTMLDocument depending
        // on doc.
        d = doc.implementation.createHTMLDocument('');
        while (d.lastChild) {
          d.removeChild(d.lastChild);
        }
        doc.templateContentsOwner_ = d;
      }
      return d;
    }
docs: http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/templates/index.html#dfn-template-contents-owner