Skip to content
November 3, 2006 / Bob Black

XSLT Error

Just a little For Your Information:

If you get the following XSLT error: <I>An unexpected end of file parsing NAME has occurred</I>, it may be because your XML file header declares the encoding as UTF-8 (or whatever), thusly:  <?xml version=”1.0″ encoding=”utf-8″?>, whilst your .net XSLT processing code is expecting a different encoding, thusly:

byte[] buffer = System.Text.Encoding.Unicode.GetBytes(XML);
memStream.Write(buffer, 0, buffer.Length);
memStream.Seek(0, System.IO.SeekOrigin.Begin);
System.Xml.XPath.XPathDocument xpathDoc = new System.Xml.XPath.XPathDocument(memStream);

Notice that the XML encoding is declared as UTF-8, whilst the .Net code is expecting Unicode (a typo). The XSLT processor doesn’t like this. Just a little something to watch out for that took me a few ticks to solve. 

This is .Net 1.1 code by the way. It’s much easier to do XSLT transforms in .Net 2.0 because there’s no need to create a temporary stream to hold XML.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: