- Simplified version, from: http://stackoverflow.com/questions/982687/how-do-i-display-xml-using-an-xslt-document-in-a-delphi-app
Uses XMLDoc, XMLIntf;function Transform(XMLContent : string; XSLContent : string) : WideString;var XML : IXMLDocument; XSL : IXMLDocument;begin XML := LoadXMLData(XMLContent); XSL := LoadXMLData(XSLContent); XML.DocumentElement.TransformNode(XSL.DocumentElement, Result)end;
I tried it, but it is really easy to use, but it has strict requirements on the XML file format.
- Supplement: if the above method is exhausted, there is a more rigorous method below.
uses MSXML2_TLB;function XMLTransform(const xmlFile: string; const xslFile: string): WideString;var XMLDoc, XSLDoc: IXMLDOMDocument2; xslTemplate : IXSLTemplate; xslProcessor : IXSLProcessor;begin XMLDoc := CoDOMDocument40.Create; XMLDoc.async := False; XMLDoc.load(xmlFile); XSLDoc := CoFreeThreadedDOMDocument40.Create; XSLDoc.async := False; XSLDoc.load(xslFile); xslTemplate := CoXSLTemplate40.Create; xslTemplate.stylesheet := XSLDoc; xslProcessor := xslTemplate.createProcessor; xslProcessor.input := XMLDoc; xslProcessor.transform; result := xslProcessor.output;end;
Don't ask me why I wrote this. I found it easy to use only one afternoon. The all-evil Delphi, really want to kick his foot when something goes wrong, if you can kick it...
- There is also a detailed description:
Http://blog.csdn.net/yethyeth/archive/2006/09/06/1187023.aspx
They are all in English. It takes a long time to read them again.