Groups | Blog | Home
all groups > dotnet xml > december 2005 >

dotnet xml : differences between XslTransform and XslCompiledTransform


Eckhard Schwabe
12/2/2005 7:33:42 PM
when switching from the old "XslTransform " to "XslCompiledTransform"
I notice a difference in the handling of whitespace. I need to transform
a XML file which contain tabs (\t), and which remain untouched when I
use XslTransform to do the transformation.
But after switching to XslCompiledTransform the tabs are transformed to
a single space in the result file, which leads to problems later on the
the program.

what I found was:
http://blogs.msdn.com/xmlteam/articles/Introducing_XslCompiledTransform.aspx

which states:

"To load the cache, XslCompiledTransform uses XmlReader to read the
input document. At this time, XslCompiledTransform applies whitespace
stripping rules."

So What I tried:

- added a <xsl:preserve-space elements="_element_name"/> to the
stylesheet. I tried various Element names, but this didn't seem to make
any difference (or I made a mistake?)

- tried using a XmlReader with "IgnoreWhitespace":

XmlReaderSettings rs = new XmlReaderSettings();
rs.IgnoreWhitespace = false;
reader = XmlReader.Create(filePath, rs);
m_XslTransform.Transform(reader, new System.Xml.Xsl.XsltArgumentList(), ms);

Both of which resultet in the same: all tabs are gone.

Is there something I can do, or do I have to stay with XslTransform?

Thanks,

Eckhard Schwabe
12/3/2005 4:29:23 PM
I found the solution for myself.

By default the XslCompiledTransform uses a XmlReader, which allways does
Normalizaion. But you can force the "old" behaviour by just giving it
a XmlTextReader instance to the transform method.
XmlTextReader does per default no normalization.

Remark: Seems like we never should have used tabs in Attribute Values to
start with.

[quoted text, click to view]
Stan Kitsis [MSFT]
12/5/2005 3:17:31 PM
You might also want to check out this blog post:
http://blogs.msdn.com/xmlteam/articles/Introducing_XslCompiledTransform.aspx

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.

[quoted text, click to view]

Eckhard Schwabe
12/11/2005 2:57:41 PM
Hello Stan,

[quoted text, click to view]

I think I read this article before, but it should be updated to clearly
state that the normalization behaviour is changed since XslTransform.

Regards,

Eckhard
AddThis Social Bookmark Button