CAbstractXslt

CAbstractXslt is an abstract class I wrote after realizing I was writing new IChannel implementations to tweak 07 CGenericXSLT just a little bit.

The abstract class

The abstract class is an IChannel implementation which applies an XSLT to an XML using some Parameters. What makes it abstract is that it asks the implementing subclass to provide each of those three things.

Things that vary

The Document

Sometimes, I wanted to get my Document from someplace other than a URL. As in, I want to get it from an in-memory cache, or from YaleInfo's DocumentCacher, or I want to generate it from something that wasn't a Document living out on the web at a URL somewhere.

The XSLT

So far a URL or relative path has been sufficient for getting the XSLT. At some point I'll realize I really did want the subclass to be able to specify something other than these as sources for the XSLT, and at that point I'll have to enhance or write a new CAbstractXslt to accomodate this, I guess. Sometimes I want to get this URL from a static or runtime channel parameter. Often I want to have a default relative-path specified XSLT that is overridable by a ChannelStaticData parameter.

Parameters to the XSLT

Often, I wanted to make parameters available to my XSLT. Sometimes these were from static or runtime channel data. Once, I wanted to make the current day of the week available as a parameter to my XSLT.

An awful lot of things have a weekly cycle. For example, suppose you want to write a channel that renders Todays and Tomorrow's Hours for the New Haven Free Public Library. So you can write a simple, static XML defining seven days worth of content. Then write an XSLT that takes as a parameter the current day of the week and parses out the relevant portion of the XML and renders it. Then extend CAbstractXslt to load that static XML document, to pass the URL where you've posted your XSLT, and to grab the current day of week and stick it into the parameter map. You're done. Then again, there's those pesky holidays... but you could programmatically check for holidays and get your XML from an alternate location on holidays...

The source code