Since publication of the example, I've received a lot of emails,
where authors are pointing out to some difficulties with encodings. I would
like to say thanks to Iasen Drenski, Bulgaria, for the help.
These difficulties appear when the users want HTML files with different than
English encodings, for example, 1251.
In order to fix the problem, there are some changes that has to
be made:
1) Change the result type of TansformDataToHTML method
function TForm1.TansformDataToHTML ( const
XMLFName, XSLFName: string ): WideString ;
2) Add a function that converts WideString into string using
correct code page
function WStr2Str ( ASource:
WideString; ACodePage: Integer): string ;
var Len: Integer;
begin
if ASource = '' then Result := ''
else begin
Len := WideCharToMultiByte(ACodePage, 0, PWideChar(ASource), -1, nil, 0, nil, nil);
SetLength(Result, Len - 1);
WideCharToMultiByte(ACodePage, 0, PWideChar(ASource), -1, PChar(Result), Len, nil, nil);
end ;
end;
3) Change SaveAsHTMLActionExecute method so the result would be
converted to the correct code page (for example 1251)
Writeln(F,
WStr2Str(TansformDataToHTML(FXmlFName, FXslFName), 1251));
To create more general application, the code page value could be
read from XML or XSL first.
Also, the result of TansformDataToHTML could be saved to the file
as WideString.