I’m using xslt 1.0 to transform some xml returned via a Server.Execute on an .aspx page. In Google Chrome if I use the following XSLT encoding:
<xsl:output method="html" version="4.0" omit-xml-declaration="yes" encoding="utf-8" indent="yes" />
I get a space left at the top of my transformed XML.
If I use this encoding:
<xsl:output method="html" version="4.0" omit-xml-declaration="yes" encoding="iso-8859-1" indent="yes" />
The space has gone, but things like £ display as �. Never truly understood which encoding I should be using. Can anybody point me in the right direction please? Thanks.
I think the problem is that when you use the utf-8 encoding the output file starts with a prefix indicating the encoding – a sequence of two characters
0xEFand0xBB, and this prefix is the extra space you are seeing.You can check if this is the case saving the file and checking if the prefix is there – and see if the problem goes away manually removing the prefix.
When using iso-8859-1 (or other non-Unicode encoding) there is no prefix, and hence no problem, but using non-Unicode encodings usually is a bad idea because it creates problems handling non-ASCII characters.
To have UTF-8 output without the prefix use an
XmlWriteras follows:where
responseis theHttpResponseof the HTTP request being served.