Following up on my earlier post about XSLT: I am drawing near the end of the first stage of my project and wanted to update my notes.
One thing I learned is that XSLT is far from dead. There was a 2.0 version of the standard released a while back that fleshed out some of the capabilities of the language, and much of the contents of XSLT have sunk seamlessly into other frameworks. The nice thing about XSLT is that it is a very compact yet flexible technology that is easy to learn the fundamentals; the reason that so many of the resources about it are older is that there simply aren’t that many lingering questions in working with XSLT that are generating ongoing discussions. It just works.
The two best resources for this project were a pair of O’Reilly books, Learning XSLT and the XSLT 1.0 Pocket Reference. I read the former over a couple of plane trips on Friday, and by Saturday night I was happily hacking away at the task that I was trying to do.
I had a couple of learning experiences with XSLT along the way, and learned two techniques that I think are worth sharing and were not documented in the O’Reilly books (though they may be elsewhere).
The first was in reordering nodes in the XML document. I had a few nested (level two) elements in my document for which I needed to take their contents (level three elements) and move them up a level in the document. But I couldn’t figure out how to do it without breaking the DTD. I finally realized that I could process any node and place it anywhere in the target set by being specific in my call to
<xsl:apply-templates> and always using a
select, rather than simply letting the stylesheet process the nodes in the order that they occur in the parent document. I will try to hack up a sample transform to illustrate what I’m talking about.
The second dealt with batch processing at the command line. Microsoft’s msxsl.exe is a nice, lightweight, fast transformation engine that can be called from a DOS prompt. Unfortunately, it does not accept wild cards for input, so you have to call it explicitly with each file to be transformed. A useful sample solution I found for XSLT batch processing using msxsl uses a VBScript in the Windows Scripting Host to enumerate the files in a source directory and calls msxsl in a loop to process them. The only problem is that the method used opens and closes a command window for each file being transformed, which is distracting and may hurt performance. I will continue to look for better methods, but for my project today this VBscript did the trick.