Problem: After migrating our solution from SharePoint 2010 to SharePoint 2013 we found an error related to custom XSL file.
The XSL itself was well formed and the generated XML also was fine but we had the below error
"Token Text in state EndRootElement would result in an invalid XML document. Make sure that the ConformanceLevel setting is set to ConformanceLevel.Fragment or ConformanceLevel.Auto if you want to write an XML fragment."
Root Cause:
Solution: After investigation I had found that there's a problem might occur in XSL with SharePoint 2013 related to referencing Javascript tags inside XSL.
Hope it helps you.
Best Regards
Ahmed Gamal