473,404 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

XslTransform.Transform, invalid character output to Response.OutputStream

When I use the XslTransform.Transform method to write to the
HttpRequest.OutputStream The first byte of the output is always an invalid
character, looks like an ascii zero or some other non-printable ascii char.
The problem is that it messes up my display.

Here is the code:
....
Response.Write("<span>some text</span>");
XmlTextReader reader = new XmlTextReader(xslFile);
XslTransform xsl = new XslTransform();
xsl.Load(reader, resolver, evidence);
xsl.Transform(xmlDoc, args, Request.OutputStream, resolver);

HTML Output:
<span>some text</span>"invalid char"<div>Some transformed html</div>

The problem is that the output should look like this:
some text
Some transformed html

But when the html parser finds the <div> tag it notices that there is
already text on the current line (the invalid char) and starts on the next
line. This adds an extra line break that looks like this:
some text

Some transformed html

Has anyone seen this before? If so is there a fix or workaround? I would
hate to have to transform to a string and then use Response.Write() to write
out the transformation

Thanks,

Tim
Nov 12 '05 #1
1 4416
Tim Menninger wrote:
When I use the XslTransform.Transform method to write to the
HttpRequest.OutputStream The first byte of the output is always an invalid
character, looks like an ascii zero or some other non-printable ascii char.
The problem is that it messes up my display.


Most likely that's unicode byte order mark (BOM). To avoid BOM
generation declare ISO8859-X output encoding in the stylesheet using
xsl:output instruction. (e.g. ISO8859-1 for Latin1 charset).
If you do need UTF-8 output, but without BOM, there is some trick:

StreamWriter sw = new StreamWriter(Request.OutputStream,
new UTF8Encoding(false));

And then

xsl.Transform(xmlDoc, args, sw, resolver);

--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Anthony Bouch | last post by:
Can anyone tell me why I receive the following compiler warning after having recently upgraded to VS.Net 2003 and .Net 1.1? Warning CS0618: 'System.Xml.Xsl(System.Xml.XPath.IXPathNavigable,...
2
by: Todd | last post by:
Hello Folks! Using http://support.microsoft.com/default.aspx?scid=kb;en-us;320847 as a reference, I am trying to pipe the results of an XSL Transformation directly out of a WebApp Default.aspx. ...
6
by: Joseph | last post by:
Hi! I have this webpage that contains some panels and buttons. I also want to output an Image to that same page, but when I save the image to the OutputStream using the Image.Save...
1
by: Bob Yuan | last post by:
Hi, I am working on a asp.net project that takes a xml source and use XslTransform.transform to generate a xhtml output. The problem with using XslTransform is that it automatically reformats...
1
by: Joseff | last post by:
I have this Bitmap object declared and outputted to the browswer this way: invoiceBMP.Save(Response.OutputStream, ImageFormat.Gif); However, the result is that the existing static controls of...
3
by: John Holmes | last post by:
I'm working with a typed dataset and want to implement a print button that prints my formatted data without the company logo and other stuff on the form. I've created an XSLT file to transform the...
3
by: kellygreer1 | last post by:
PHP will alllow you to build up an entire page and before sending that out as the response.... you can grab all the text and do search and replaces, add comments, make more CSS/XHTML compliant,...
1
by: qbp90x5lb | last post by:
I'm using an XSLT transform to output the element value contents from a simple XML file into a new .TXT file. Everything works fine except for certain XML files, when calling msxsl with the .xslt, I...
1
by: sudhaMurugesan | last post by:
Hi all, I am using VS2003. I am new to VS2003. I cannot transform an xml file into a string output in my windows application. But the same function works well with VS2005. it also asks for...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.