Chaotic PatternExclusively Symphony, straight from the source

To enrich your experience, look sideways

A 12-hour driving trip from Brisbane to Sydney can sometimes shield the driver from the side-view windows – with only one thought in mind; to get to the destination. Take a break, the journey is every bit as good as the destination.

Symphony is soon reaching version 1.8. It’s over two years old and it’s been around its fair share of blocks. Symphonians now expect more features, greater stability and fewer bugs. The Symphony team is every bit as committed to these but because of it, we sometimes lose sight of existing features that need a little bit of tender, love and care. Each of the members in the Symphony development team have their own pet peeve with the system that we vow to one day fix. In this article, I will illustrate one of my pet peeves.

So a clutch is called paper towel and the steering wheel is Bono?

Very early in Symphony’s development we came up with the idea of reusable XSLT code snippets called Utilities. A feature along the same line is Masters, which are also reusable XSLT code. In retrospect, the implementation of these features are a little odd. To include an Utility or Master in a page, you select the ones you want associated to a page. When the appropriate page is called, PHP will inject the selected Utility and Master code into the XSLT document. This sounds logical, doesn’t it? Well, not really.

As our main development rule, we strive to keep the templating layer in Symphony as transparent as we can possibly make it. Developers with prior XSLT knowledge should able to understand and integrate their knowledge into Symphony without having to troll through documentation. It’s not quite the case at the moment. Data sources, events, Utilities and Masters are all Symphony specific functions and terminology. From the XSLT developer’s point of view, all they are concerned about is XML, XSLT and XPath. Worse still are the XSLT beginners trying to grasp the idea of both Symphony and XSLT at the same time. They are often confused by the mix of these terminology. Where Symphony ends and XSLT starts can be a very daunting learning exercise, and this is a counter-definition of what a “transparent layer” means.

Utilities and Masters are specific terms in Symphony but to an XSLT developer, they are simply XSLT documents. I don’t actually mind the use of these Symphony terms. It’s convenient to ask other Symphonians in the community: “can someone post a date formatting Utility?” or “I think my Master for outputting a CSV file isn’t working”. However, when Symphony go so far as creating specific inclusion methods and dedicated user interface elements for these, it’s no longer simply defining these terms as characteristics, it’s now actually classifying them. Users no longer identify them as what they truly are but something else entirely. This brings me to the the next issue.

It’s got cruise control, use it

As we have just established, the process of including Utilities and Masters into a page is done by PHP hijacking the result of the source XSLT document and inserting them between the <xsl:stylesheet> element. It goes without contention that hijacking is bad. To a developer with XSLT background, this occurrence is both unexpected and just plain weird - nobody likes their source document snatched and modified.

The reason why it’s a particular pet peeve of mine is that XSLT already have instructions for this occasion. It’s called <xsl:import> and <xsl:include>. In fact these XSLT instructions are far more powerful than Symphony’s current method.

<xsl:import> acts similarly to Object Oriented Programming principal of class inheritance. It even allows multiple inheritance. The beauty of functional-based languages are that there are no discernible differences between single inheritance and multiple inheritance. Function overloading, inheritance and higher-order functions are simply in the genes of XSLT.

So why did we go with the method we have now? The below describes 3 reasons:

  1. To include an Utility via the <xsl:include> method, the target document must be a valid XSLT stylesheet. i.e. complete with the <xsl:stylesheet> element. Currently, Utilities are just <xsl:template> snippets.
  2. Including external files have the potential (I say this without proof or research) to be less efficient than having all the code inside a single document. I’m basing this off our experience with the highly inefficient document() function.
  3. Portability. The current method inserts all associated Utilities and Master in an XSLT page so going to ?debug will yield a single complete XSLT document.

Looking back, the above reasons are not legitimate issues. Regarding the first point, my fear was that having Utilities as full-fledged XSLT documents could seem complicated for some. However, it’s apparent now that having this voodoo-crazy-body-snatching-magic is equally as complicated for someone new to wrap their head around. Plus, if someone is to learn the system, it’s much better for them to learn it the proper way with <xsl:include>.

Regarding the second point, I have yet to do some serious benchmarking with the heavy use of <xsl:include> and <xsl:import>. This should prove to be an interesting exercise. My prediction is that if the included XSLT document is local, the instantiation of the XSLT document should be equally as fast, with only a slight increase in overhead.

The third and last concern is actually very interesting. I’ve once thought that being able to go to ?debug to see my fully working, self-contained XSLT document is a good thing. Whilst it’s good in some cases, it completely overshadows the point of reusability. This concept is parallel to CSS in HTML. Currently, Utilities and Masters are like inline CSS whilst the idea of using <xsl:include> and <xsl:import> are like external CSS. The point of abstracting code to external file is to allow common reusable elements to be edited once and applied globally. Further more, this external XSLT document would be self-contained and standalone, promoting reusability and allow the code to be shared amongst the XSLT community and not just specific to Symphony.

Pedal to the metal, let’s get there!

My goal is to one day abolish the current way of including Utilities and Masters and instead rely on XSLT’s built-in mechanism for including such things. Of course, there will still be a clean and elegant interface to simplify the process. For example, on a new Symphony page, a list of XSLT documents will be presented on the sidebar - selecting a document will automatically insert the appropriate include/import instruction into code editor. Unfortunately, currently there are no plans to implement this change into Symphony but it’s something the team is eager to implement in the future.

Discussion

Driving on the wrong side of the road is your thing? Maybe you like throwing two cents at oncoming traffic. Whatever the case, let us have it!

Almost-guaranteed discussion of intrigue

Mark Lewis 22 June 07Wordfest participantWordfest word awardWordfest Starting Phrase awardWordfest character limit award

No more excuses. I downloaded Symphony expecting a robust XSLT CMS and all I got was a Bonnet.

I would be interested to hear the result of your speed tests using import and include. Very good article. However, there’s always the problem of current users upgrading. Significant changes would have to be made across the board throughout templates.

I for one, love the idea; I just wish you’d thought of it sooner ;-)

Allen 22 June 07

Legacy support is the main reason why there are no plans to implement this into Symphony. The solution is to either create some kind of Utility and Master conversion script, which in itself is a monumental task or alternatively branch Symphony into 2 versions. Many open source developments have been through the forking road, but that completely assimilates code simplicity and elegance.

Nathan 22 June 07

I think Allen you raise the most practical approach for the short term, branching Symphony into 2 versions would allow new comers (like myself) to step straight into the XSLT import/include driven system and also allows others to move over in time. The main problem with this however is where do you cut long term support and updates to the “older” version so you can concentrate your efforts on the “newer” version?

I think talking about it (as you are) is at least a step in the right direction because from what I’ve seen of the community building around Symphony everyone seems to be attracted by it’s elegance, I’m sure if the prospect of enhancing that elegance was put to the community you’d find that the majority would support the idea. Personally, if I knew that Symphony was going to move in a new and improved direction and I had some idea of when this was going to happen (and possibly what I should expect) I be happy to redo what I’d already done, either immediately of a little further down the track. Honestly, it would be a small effort on my behalf compared to the effort you have made to give users such a great tool.

Well that’s my 2 cents..

Cheers.

Mark Lewis 23 June 07

After a quality night’s sleep, I’m pondering how Pages would fit into this new approach. Pages, again, are simply XSLT documents with one difference: Pages aren’t reusable. I believe consistency is a big part of increasing usability and lessening the learning curve.

You would expect them to take this same new approach. Obviously, Pages will always incorporate some voodoo-like-magic to serve content dynamically. Perhaps this approach needs to be changed too (even if only to remain consistent).

Wouldn’t not doing so leave then an exception?

Allen 23 June 07

Mark makes a very interesting point about Pages and its comparison to other “plain” XSLT documents. Full explanation to this would be the length of an entirely new article, so I’m going to cut to the juicy bits (in note form):

  • The only dynamic element in a Symphony page are URL parameters. These are served as command level values passed to XSLT documents as global parameters. In other words, PHP passes the dynamic values into XSLT documents via function calls. This method is actually specified in the XSLT specification. In fact, that is one of the reason why parameter overriding is such an awesome technique.

  • URL parameters were originally injected into a document much like Utilities and Masters, which is definitely voodoo-like as Mark explained. However, since 1.6 (if I recall correctly) Symphony has been using command level parameter passing method, except if the server is running on Sablotron. The reason isn’t that Sablotron cannot do command level parameter passing, it’s that global and local parameter’s priorities are different compared to all other XSLT processors. However, having Sablotron utilise local parameters makes it behave like all other processors. By my count, Sablotron is already 3 strikes into non-conformity. In spirit of consistency and no voodoomagicness (yes, one word), we may eventually pass parameters via command level regardless of processor - developers just have to be content with Sablotron being a rebel against standardisation.

  • Mark is right about the fact pages are not reusable. To make full sense of an XSLT document in Symphony, you need to give it more information regarding a page. For example its handle, URL parameters, what type of page it is (index, XML, default or custom), etc. However, I see this kind of meta information to be akin to the challenges XSLT developers face working outside of Symphony. How is the page used, when does it get called and what variables does it have to deal with are common questions that a developer would need to know regardless of their environment.

Kwok Ting Lee 23 June 07

Well, from my perspective, anything that improves elegance is a good thing. As long as the switch is announced early enough, I think most real Symphonians would be on top of it and be able to adjust their code to the new way of doing things. In this regard, I’m in agreement with Nathan.

yfhahn 24 June 07Wordfest participantWordfest word awardWordfest Starting Phrase awardWordfest character limit award

No more excuses for utilities – perhaps we should start thinking of these as libraries. After all, there have been lots of utilities that are serving as quick ways of adding necessary features or something like an API to your code. The date/time utility, for example, is a pluggable way to get some nice formatting features right in your XSLT. I have my own set floating around–date compare, tree structure, etc.

It may be worthwhile to consider adding some sort of Symphony-specific type/field/tag handle to data sources and custom fields. For example, say I write a utility/library that should work with any sort of “blog post”, that is, a data source that pulls from a section with Author/Date/Title/Body/CF-link-tags. But seeing as I don’t know the exact names of these fields, I can’t abstract my library beyond my own site–another symphonian would have to alter my library to work with hers.

But what if Symphony added developer attributes to its CFs so that a long textfield was tagged as such, a select option as such, etc. ? Then I could generalize my library so that it could work with anyone’s site, regardless of whether they called their blog post “Body” or “Bonnet”.

Then we start to see some real drop-in utilities. Suddenly Symphony goes from developer heaven to requiring almost as little effort as ye old Wordpress.

Maybe that would be a bad thing.

Calrion (Greg W) 27 June 07

Bring it on, I say!

To my mind, one of the biggest advantages Symphony has over other systems is its use of XSLT. That, and that it’s designed as a CMS, not blogging software.

Provided due notice and documentation is given, I see no problem with having to re-work a few things when I upgrade to the new version. Just do it!

On the pages thing, perhaps a ‘page’ simply becomes metadata tied to a template. That is: “Create a new page. It has this name, this handle, uses this datasource, etc. And base it on this XSLT stylesheet over here. Thanks.”

Stephen Bau 28 June 07Wordfest participantWordfest word awardWordfest Starting Phrase awardWordfest character limit award

No more excuses, if this is the best way to build Symphony. Rather than obscure the ideal of the perfect web publishing app by continuing along a less than ideal path, rip the bandaid off and stick a Bonnet on it. This sounds like a version 2.0 change, but I’m happy to weather the changes, be they major or not. And I’ve seen a lot of changes since the beta release. After 1.8, we’ll have a full-featured system that will be able to handle many types of sites for as long as it takes us to grapple with a new way of doing things.

(You’re right. It is hard to write this post without 11-letter words.)

Allen 28 June 07

Without 11 letter words can be hard, but wait until I ban the use of 2-letter words!

Emit your deadly intellect rays