delphi里的xml组件能否利用xsl做转换?(50分)

M

mor

Unregistered / Unconfirmed
GUEST, unregistred user!
在delphi里能否实现:一个xml文件/dom对象根据xsl转化成另一个dom对象?
 
可以,使用MSXML解析器,用下面这个函数:
functiondo
Transform(const xml, xsl : string ): string;
var
XMLDoc : IXMLDOMDocument;
XSLDoc : IXMLDOMDocument;
Template : IXSLTemplate;
Processor : IXSLProcessor;
begin
Result := '';
try
XMLDoc := CoFreeThreadedDOMDocument30.Create;
XSLDoc := CoFreeThreadedDOMDocument30.Create;
XMLDoc.load(xml);
XSLDoc.load(xsl);
Template := CoXSLTemplate30.Create;
Template.stylesheet := XSLDoc;
Processor := Template.createProcessor;
Processor.input := XMLDoc;
Processor.transform;
result := Processor.output;
finally
XMLDoc := nil;
XSLDoc := nil;
end;
end;

 
同意,就是这样,不过如果用自带控件可以更简单一点
 
顶部