This is similar to my previous post (same root cause), but is is a more impactful than the XML fragments case.
If the XSL is generating a non-XML output like this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" >
<xsl:output method="text" />
then the same error happens as with the fragment (e.g. InvalidOperationException: Token Text in state Start 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.)
This is caused because an XDocument is used to create the XmlWriter passed to the Transform method instead of creating an XmlWriter using the OutputSettings that is available from the XslCompiledTransform class after the XSL stylesheet has been
loaded. The XmlWriter returned from the XDocument is configured to only allow a well formed XML document to be created.
I really needed to get this working, so I've made the changes required to get this scenario (and the fragment scenario) to work. I'd be happy to contribute these changes, but I've not used CodePlex before from a contributer standpoint, so I'll need a bit
of guidance on how to get enlisted into the source control project or how to package up a patch.
Just let me know how you'd like to proceed.