XHTML and Domain Specific Languages (DSLs) and Stylesheets.

This is the fifth installment of our XHTML/HTML series. Extending the notion of using other, W3C-approved XML, extension languages along with XHTML is the idea of completely replacing the XHTML content with simpler XML content.  Domain Specific Languages (http://en.wikipedia.org/wiki/Domain_Specific_Language) are generally computer languages which have been specifically designed with solving problems in a specific domain.  The notion is that frequently-expressed concepts work their way into the statement of the problem, rather than being expressed in the solution to the problem.

The same approach can be used with XHTML.  Because it is possible to use a stylesheet to transform any tree within an XML document, and because so much of what makes a web page is boilerplate, it is possible to extract the boilerplate into a stylesheet and then use that to define a domain-specific language.

A Simple Example

A simple example should suffice to demonstrate this approach. Imagine that you are running a bookstore, and you have information about your books stored in XML somewhat as follows:

<book>
      <title>Arthur's Tree House</title>
      <author>Marc Brown</author>
      <coverImage>8037.jpg</coverImage>
      <price currency=”USD”>399</price>
</book>

By simply adding the following two lines to the top of this file (and providing all the referenced stylesheet information), you can automatically transform this into a complete XHTML page:

 

<?xml version="1.0" encoding="utf-8"?>

<?xml-stylesheet type="text/xsl" href="BookClub.xslt"?>

This works because the browser knows when downloading an XML document with the xml-stylesheet processing instruction to automatically apply the specified stylesheet before attempting to display the page.  The stylesheet generates XHTML output, which the rendering engine knows how to display in the browser.  The CSS styling (attached within the XSL stylesheet), provides the style, completely separated from the content.

Did I lose you?

Apologies if that didn’t seem as simple as the title suggested.  The principle is that creating the content pages should be simple – because much of the complexity has been sucked up into the XSL stylesheet.  And the mechanism for triggering this – identifying the stylesheet within the file – is also simple.

Writing XSL transformations themselves, however, is not so simple.  But it does hold great advantages when you have truly domain-specific information, as in this case, which you might want to use in numerous different ways in a single site.  For example, you might want to display books in each of the following contexts:

  • On their own page, where all the information about the book is shown;
  • On a recommendations page, with just the cover and the title;
  • In a list (such as the shopping cart) without the cover image.

And in each context, exactly the same XML file could be used, but with a different XSL stylesheet on the page to make a different transformation to different XHTML.

In Summary

The power of XML, specifically with regard to XSL stylesheets, can be leveraged within XHTML to reduce the complexity of making individual documents and to promote reuse.  The value of this technique depends on the other elements that collaborate to form your complete system.

Add comment



 



Country flag





download aggiorno

About Aggiorno

Aggiorno - a plugin for Visual Studio - is your instant ticket to SEO friendly, XHTML compliant, CSS styled HTML and ASP.NET! Read more on What is Aggiorno?

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in

Subscribe to Rss Feed