I am using C# 3.5. I have an XML string that I pass to XslCompiledTransform object. I then display the output in a WebBrowser. All is working great except that the XML elements contain extra spaces which I need to display in the WinForms HTML browser. I can't use any javascript in the html. Here is a sample XML element:
<myelement>Here is where extra spaces need to be retained</myelement>
I tried replacing the string " " with " "
but that made the xml that the XslCompiledTransform object used to transform invalid (the XML is invalid). Then I tried replacing " " with "&nbsp"
but then the text &nbsp;
appeared in my html instead of a space. How can I get the extra spaces to appear?
Add
to your xsl stylesheet or your input doc.
Here's a thorough guide to whitespace handling in XSLT.
EDIT:
To retain white space in the rendered HTML, use css style
white-space:pre
on the element in which you want to preserve white-space.