Thursday, 15 May 2014

c# - XSLT not encoding double byte characters -


I am working on an audience to display XML log files using XLL. Everything is going to be alright My Localization As a result the HTML file has '³' where there should be some double byte characters I can not understand what I am doing.

Here's an ASASSLT file:

  & lt ;? Xml version = "1.0" encoding = "UTF-8" & gt; & Lt; Xsl: stylesheet version = "1.0" xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" xmlns: fn = "http://www.w3.org/2005/02/xpath- Actions "& gt; & Lt; Xsl: output method = "html" version = "4.0" encoding = "UTF-8" indent = "yes" /> & Lt; Xsl: select variable name = "language" = "nbklog / @ language" /> & Lt; Xsl: variable name = "dictionaryName" & gt; Dictionary_ & lt; Xsl: Select Value = "$ language" /> .xml & lt; / Xsl: variable & gt; & Lt; Xsl: Select variable name = "dictionary" = "document ($ namename)" /> & Lt; Xsl: template match = "/ nbklog" & gt; & Lt; Html & gt; & Lt; Body & gt; & Lt; H2 & gt; & Lt; Xsl: Select Value = "$ dictionary // string [@ key = $ job type]" /> & Lt; / H2 & gt; & Lt; / Body & gt; & Lt; / Html & gt; & Lt; / XSL: Templates & gt; & Lt; / XSL: stylesheet & gt;   

The XML file used for localization is:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Dictionary xml: lang = "es-ES" & gt; & Lt; String key = "application" & gt; ApplicaciĆ³n & lt; / String & gt; & Lt; / Dictionary & gt;   

Here's an example xml file to be transformed:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Nbklog id = "51b654d4" job type = "backup" language = "es-ES" version = "1.0" & gt; & Lt; DEVICENAME & gt; C: \ & lt; / DEVICENAME & gt; .... & lt; / Nbklog & gt;   

I am performing the following C # code in the change:

  string theOutputHtml; (MemoryStream MS = Using new MemoryStream ()) (Exclamation text writer Writer = new XMLTuccessor (MS, Encoding. ITF 8)) {XPathDocument theDocument = New XPathDocument (InxmlFilmemeM); // Load the style sheet and run the changes. XslCompiledTransform theXslTrasform = New XslCompiledTransform (); Thexsltrasform.load (inXsltFilename, XsltSettings.TrustedXslt, tap); Xlstrosform Transform (The Document, Author); Ms.osition = 0; (Using the StreamReader theReader = New Stream Reader (MS)) {theOutputHtml = theReader.ReadToEnd (); }}}   

Output will contain '³' instead of 'O' in HTML content.

Edit:

By adding it to HTML strings and between tags, my problem has been solved:

 < Code> & lt; Meta http-equiv = 'content type' content = 'text / html; Charset = UTF '& gt-8;    

change new XmlTextWriter (MS, encoding.ASCII) A new potential issue is that although your XML files are a encoding = "UTF-8" declaration, probably the file is not actually saved from that encoding, check that all your XML files encoding their Declares the encoding, personally, I prefer to stay away from declaring the encoding so that it's a Who have to be searched.

No comments:

Post a Comment