Clementson's Blog

Bits and pieces (mostly Lisp-related) that I collect from the ether.

November 2004
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Oct  Dec

XSLT-like processing in CL

Wednesday, November 3, 2004

I frequently need to process XML documents. In the past, I've used XSLT for this; however, XSLT is a pain to program in since it is a verbose, XML-based language. Also, although XSLT is a very powerful language for transforming XML documents, I find that I usually use only a core subset of its features. Therefore, I've been using CL in place of XSLT for the transformation-type XML processing that I do. XSLT lets you use a declarative approach if you like; however, the more common usage pattern is functional and data-driven, with different transformations occuring based on the application of element-specific templates against the XML. It is this latter type of usage that I decided to replicate in CL and I've written a very basic library to do so.

The library is called XML-XFORM and it depends on the XMLS XML parser written by Miles Egan. XML-XFORM is installable with ASDF and has been tested with ACL, CLISP, and LispWorks; however, it should work with any CL implementation that is supported by XMLS. The exported symbols are:

As an example of how XML-XFORM can be used, I have created a program that transforms an XML version of my work history into an HTML resumé. The program uses XML-XFORM as well as the KMRCL and LML2 packages written by Kevin Rosenberg. Since resumés should be tailored to specific jobs, the default processing is to produce a short, tailored resumé containing a summary of experience pertinent to that particular job. However, since I like to maintain a lot of detail about my previous work that I may not want to appear on a specific version of the resumé, The xform function that generates the resume has an optional "detail" parameter which controls whether the full detail is printed out or not. When that parameter is set, additional work detail as well as details about non-work projects are printed. Here are the main components of the example: A logical next step would be to use XML-XFORM with Marc Battyani's CL-TYPESETTING library to create a resume-pdf.lisp program that generates a PDF version of the resumé so that there are both on-line and off-line versions of the resume.

emacs Copyright © 2004 by Bill Clementson