For some reason, I'm unable to access contents of <template> nodes. As a workaround, I had to write a custom simple HTML tokenizer / parser, to replace all <template> with something else, e.g. <template_>, process the HTML, and then put back the <template>.