Correct handling of the <template> tag content fragments. Fixes #942

Fix for #942