I’ve become a zealot about using Rule-based engineering as an approach to creating highly agile applications. The guy that taught me most about rules-based programming is Andy Seidl, my co-founder at MyST Technology Partners.
Rule-based XSLT
Andy started us on the rules-based track about three years ago while we were trying to develop a new type of content platform; one that would be very agile. In doing so, we found some interesting ways to create new and flexible business logic with very small pieces of XSL code. The whole idea - as simply as I can state - leverage the power of XSL templates to create code that simply executes (or doesn’t) based on the context discovered in the XML result document being transformed.
Rules in Practice
As a good example, the other day I had an idea to create a “brandroll” - similar to a blogroll but for brands that a business blog might mention in their weblog. I also wanted to create this new feature in a way that provides more relevance between the blog post where a brand is mentioned and the visibility of such brand reference in the blog. In my view it makes little sense to display links to other resources (such is the case with blogrolls) just because you like those authors or that content. Search engines don’t like disjointed references - they prefer to see links from point “A” about subject matter “X” to point “B’ also about or closely related to subject matter “X”. I concluded that we could elevate the science of “rolls” with a requirement that a brandroll reference on your blog must be contextual - i.e., references to blogs (or brands) might serve blogsite visitors better if the roll is dynamic — oddly enough, XSL-based rules provide a very efficient way to achieve this.
Since our own Blogsite technology is based on XML result documents that use XSL to transform them into all sorts of output including HTML user interfaces, it was pretty easy for me (a fairly inexperienced XSL programmer) to create the functionality I was looking for. Instead of implementing the brandroll as a static link in a navigation page, why not allow bloggers to call out discrete brands with meta-objects as they write content? This has many benefits - your brandroll builds in a natural way and in concert with actual writings about the brands plus the brand data can be used in alternative ways later on. This required a new information object type which I created in Blogsite’s Structured Details environment - this is similar to WordPress’ custom attributes capability but a bit more robust (I’ll write more about this someday).
Example Brand References as Custom Attributes
An example of some associated objects can be found attached to this blog author’s profile page - scroll down to see the profile object and two brand objects. These are part of the item in the MyST platform and to get a better understanding of the structure, take a peek at the XML representation (before the presentation layer had a crack at it) at this address (note that we simply change the URL to request /object instead of /item):
http://blog.wavgroup.com/public/object/153968
In this document you’ll see the structured details representing the brand items - Fischer-Price and Surveyor Corporation. On the navigation pane (lower right) is the brandroll - if you navigate away from this particular profile to say Mike Audet’s profile, you’ll see the brandroll change to reflect only brand references related to his profile. Lastly, if you navigate to a page that shows all profiles, the brandroll will include all brand references related to all profiles.
These are simple ideas, but programming them are just as simple because all I had to do is add a rule that fires when (and only when) the context suggests a UI transformation is needed. And of course, there are requirements where more than one context may apply - for example - a collection of content items that contain brand references need to display all brands in that collection …or… while looking at a single content item that contains brand references. In the MyST platform we provide two different XML result documents for item collections and individual items.
To achieve this level of agility and simplicity in XSL, the following apply-templates fits the bill for the XML result document referenced above. It is called as a parameter to the template (i.e., rule) named GENERATE-BRANDROLL-INDEX and shown below.

The X-Path above seems a bit complex, but it’s really quite simple - here’s a walkthrough…
- The .//Item… allows us to recognize two different contexts - when the document is a collection of MyST item resources as well as when we are requesting a single item resource.
- With Collection.Brand_Reference we zero in on only brand references.
- The not(… Hidden = ‘true’) allows us to avoid matching embargoed items.
- The not(@name = preceding::sd:Collection/@name) provides a way to .provides a simplw way to avoid displaying duplicate brandroll items.
The only code necessary beyond the apply-templates is the rendering rule shown below which leverages existing (and more generic) rules for displaying subheadings and links in navigation panes.


Email

0 responses so far ↓
No comments yet... be the first!
Leave a Comment