We have done something similar at our site, but we had to remove the comment <!-- mapserver version and modules... -> from the CGI because it goes out before the template and therefore before the line <?xml version="1.0" encoding="UTF-8"?> And thats not legal XML if you got a picky parser otherwise it works like a charme.