<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>XML &amp; Tools</title><link>http://blogs.msdn.com/sdub/default.aspx</link><description /><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Confession</title><link>http://blogs.msdn.com/sdub/archive/2008/03/04/confession.aspx</link><pubDate>Tue, 04 Mar 2008 08:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8019684</guid><dc:creator>sdub</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/sdub/comments/8019684.aspx</comments><wfw:commentRss>http://blogs.msdn.com/sdub/commentrss.aspx?PostID=8019684</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: right" align=right&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;I promised &lt;A class="" href="http://blogs.msdn.com/antosha/" target=_blank mce_href="http://blogs.msdn.com/antosha/"&gt;Anton&lt;/A&gt; to write a confession so here we are.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;&lt;FONT size=+0&gt;&lt;FONT face=Calibri&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;I am confessing that in Orcas we did a breaking change in the XslCompiledTransform. &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;Scenarios that load XslCompiledTransform from the XmlTextReader may handle whitespaces differently in the Orcas and in the Whidbey. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;U&gt;Preamble&lt;/U&gt;:&lt;/B&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;.NET Framework&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;2.0 introduced new implementation of XmlReader to read XML from text stream. This class doesn’t have any public name and can be instanciated by call to XmlReader.Create() method. Let’s name it here “new reader” to distinct from XmlTextReader – the “old reader.”&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;“New reader” is faster and more W3C compliant, but fixing compliance bugs often result in breaking old behavior. For this reason Framework 2.0 was shipped with two xml readers “new” and “old”.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;One thing that was fixed in “new” xml reader is whitespace handling. “Old” reader considered “ &amp;amp;#32; ” as a text node; “new” one reports it as whitespace.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;XslCompiledTransform when it performs whitespace stripping need to distinguish whitespace nodes&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;from text nodes. In Whidbey it relies on node type reported by xml reader. Some readers report it incorrectly. XmlNodeReader reports all whitespace nodes as text nodes and for this reason you can’t load stylesheet with element like this:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;&amp;lt;xsl:include href=”foo.xsl”&amp;gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;&amp;lt;/xsl:include&amp;gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;New line inside of element would be considered a text node and XslCompiledTransform would report a syntax error.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;XLinqReader also decide not report whitespaces correctly and to avoid compatibility issues with XslCompiledTransform last one doesn’t trust XmlReader on whitespaces anymore and detects whitespaces itself.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;U&gt;The Problem&lt;/U&gt;:&lt;/B&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Some users used the fact that “old” xml reader reports “ &amp;amp;#32; ” as text and used it as a way to control whitespace stripping process during XSLT load. When they want prevent WS from stripping they represented it as entity.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;(Once again, this did work only when XslCompiledTransform.Load() called with “old” xml reader.)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;This was not W3C compliant behavior and the trick would not work in Orcas version of Framework.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;U&gt;Workaround:&lt;/U&gt;&lt;/B&gt; The best solution is fixing the stylesheet by replacing “ &amp;amp;#32; ” to &amp;lt;xsl:text&amp;gt; &amp;amp;#32; &amp;lt;/text&amp;gt; or just &amp;lt;xsl:text&amp;gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;/text&amp;gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;If you have any stylesheets which were hurt by this breaking change and can’t process them by hands you can always write program that reads each of them into text buffer, creates both “old” and “new” xml readers over this buffer and compare results of these readers.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Text nodes that reported by “old” xml reader as WS this program would wrap with &amp;lt;xsl:text&amp;gt; element. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: right" align=right&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8019684" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/sdub/archive/tags/XmlTextReader/default.aspx">XmlTextReader</category><category domain="http://blogs.msdn.com/sdub/archive/tags/whitespace/default.aspx">whitespace</category><category domain="http://blogs.msdn.com/sdub/archive/tags/XslCompiledTransform/default.aspx">XslCompiledTransform</category></item></channel></rss>