Use XSLT to convert XML file formats in Delphi

Source: Internet
Author: User
Tags xsl
  • 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.