на главную   |   А-Я   |   A-Z   |   меню


Листинг 9.1. Использование XSLT-преобразования в Delphi

unit source;


interface


uses

 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

 StdCtrls, ComCtrls, MSXML2_TLB, comobj;


type

 TMain = class(TForm)

  { Компоненты формы и обработчики событий }

 private

 public

 end;


var

 xmlSource: DOMDocument;

 xmlStylesheet: DOMDocument;

 Main: TMain;


implementation


{$R *.DFM}


procedure TMain.FormCreate(Sender: Tobject);

begin

 xmlSource := CoDOMDocument.Create;

 xmlStylesheet := CoDOMDocument.Create;


 try

  xmlSource.load('source.xml');

  memoSource.Text := xmlSource.xml;

 except

  on e: EOleException do

   memoSource.Text := e.Message;

 end;

 try

  xmlStylesheet.load('stylesheet.xsl');

  memoStylesheet.Text := xmlStylesheet.xml;

 except

  on e: EOleException do

   memoStylesheet.Text := e.Message;

 end;

end;


procedure TMain.pcMainChange(Sender: TObject);

begin

 if pcMain.ActivePage = sheetResult then

 try

  memoResult.Text := xmlSource.transformNode(xmlStylesheet);

 except

  on e: EOleException do

   memoResult.Text := e.Message;

 end;

end;


{ Прочие процедуры и функции }


end.

Процесс использования нашего приложения приведен на следующих рисунках (рис. 9.4–9.6).

Технология XSLT

Рис. 9.4. Входящий документ

Технология XSLT

Рис. 9.5. Преобразование

Технология XSLT

Рис. 9.6. Выходящий документ


Использование DOMDocument | Технология XSLT | Выполнение XSLT-преобразований в C/C++