AODC – separating content, structure, format and behaviour
This week I’m attending the Australasian Online Documentation and Content Conference (AODC) on the Gold Coast in Queensland, Australia. With his inimitable flair and style, Dave Gash presented a session this morning entitled “The Search for the UA Grail: True Separation of Content, Structure, Format and Behaviour”.
Dave is the owner of HyperTrain dot Com, specialising in training and consulting for hypertext developers. Today he told us what’s wrong with the way we traditionally do things, what’s wrong with the conventional wisdom on how we might improve our way of working, and what’s a better way.
What’s wrong with the traditional way we do things
The basic problem is that we write our content, e.g. a web page, and tweak elements of it on the fly. For example, we might make some text bold, or colour other text, or whatever. The result is spaghetti code — difficult to maintain and share.
What’s wrong with the conventional wisdom on improving the above situation
People usually say we should “separate format from content”. But what is “format”? That term is too vague. And the phrase implies that everything that’s not “content” is “format”. Wrong.
The better way
We should separate our document into four components instead of two:
- Content (which you might realise via XML)
- Structure (XSLT)
- Format (CSS)
What we’re aiming for:
- Maintainability — you can change one of the above four components without breaking the others.
- Separation of skill sets — different people can work on the component they know best and enjoy most.
- Simplified updating of content — content is likely to be the component you update most often.
How to do it
- Dave’s tip: You don’t have to specifically code the “I’m through hovering” handler because it’s implicit in the pseudo-class.
- Move all CSS styles to an external file. Convert local formatting to classes too.
- Dave’s tip: If the boss says “Change the list spacing in all lists on all pages”, it’s in one spot — change it and take the rest of the day off.
- Add semantic markup to the content, using XML.
- Now it’s time for some XSLT. Identify the output HTML you want, then write the XSL transforms to produce it.
- Write small, individual templates to create the HTML for each specific XML tag. Then use the “magic” <xsl:apply-templates/> element to pull it all together. This nests the processing of the templates, so that the transforms will just keep happening for each XML element, hierarchically down and back up the tree, until they’re all done.
Dave has made the code available on the “Downloads” tab of the HyperTrain dot Com web site.
A recommended editing tool: EditPlus.
Thank you for a great session, Dave. And a special thanks for changing “behavior” to “behaviour” throughout your presentation, just so that we Ozzies felt comfortable 😉