Web development without Internet Explorer

As a matter of fact, for years Internet Explorer has slowed down the global development of web standards and, more broadly, the entire future of the web. For years web developers have been forced to, as Ian Hickson says, code to the lowest common denominator instead of coding to the standards. As a result, now many developers still use a small percentage of the full potential of web standards not because they don't know how to code properly, but because they're afraid of what consequences might result in Internet Explorer.

For example, all JavaScript frameworks devote a significant amount of their inner routines to mitigate the differences between Internet Explorer and the other browsers. Further, the power of CSS3 features is still underused because of the support in Internet Explorer which is still far from getting the level of Firefox, Safari, Chrome, and Opera. What's more, XML and XSLT still rely on the presence of the MSXML library to exploit all their potentialities to the full. Finally, the most advanced features of the latest DOM specifications are still a theoretical thing in Internet Explorer.

How much time we devote to rethink a full website in terms of compatibility with IE? Sure, we're talking about backward compatibility here, the same thing that should make the web look like the old, good '90s, with GIF animations, dial-up modems and no AJAX, no CSS, all tables and, if we are lucky, JavaScript popups. Do you really think your web development process in terms of backward compatibility? I think the majority of developers would all agree to view the web from the forward compatibility point of view. Do you really like the idea of writing a CSS file made up only of class and ID selectors? I guess not.

Do you really enjoy the practice of duplicating your code when you want to use XPath on Internet Explorer? Do you still like all the quirks, bugs, inconsistencies that come along with IE's implementation of web standards? That's quite masochistic, in my opinion. Instead, rethink the web in terms of new features that may be added now, today or in the future. Embrace the future, not the old, sinking relics of a bigon age when the e-mail was the only practical implementation of web communication.

In a nutshell: test in Internet Explorer, if this makes you feel relieved but code just as if IE doesn't exist.

An XML blog with CSS and XSLT

In order to create a blog in XML, we need a basic XML template. Here's a possible template inspired by Wordpress:

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

<document>

 <page>


  <headerimg>
  
   <h1>XML blog</h1>
   <description>a Wordpress blog</description>
 
 
  </headerimg>
  
  <content>
  
   <post>
   
    <h2>Story Heading</h2>
    <date>April 3, 2009</date>
    
    <entry>
    
     <p>
     </p>
     
     <postmetadata>Posted in <link url="#">Category</link> | <link url="#">Comment »</link></postmetadata>
    
    </entry>
   
   </post>
  
  </content>
  
  <sidebar>
  
   <h2>Archives</h2>
   
   <ulist>
    <item><link url="#">April 2009</link></item>
    <item><link url="#">March 2009</link></item>
   </ulist>
   
   <h2>Categories</h2>
   
   <ulist>
    <item><link url="#">category 1</link> (3)</item>
    <item><link url="#">category 2</link> (7)</item>  
    <item><link url="#">category 3</link> (5)</item>
   </ulist>
   
   <h2>Meta</h2>
   
   <ulist>
   
    <item><link url="#">XML</link></item>
    <item><link url="#">Wordpress</link></item>
   
   </ulist>
   
  
  </sidebar>
  
  <footer>
  
   Gabriele Romanato
  
  </footer>


 </page>


</document>

As you can see here, our document is without any style information attached to it. The first thing we're going to do is to use XSLT to transform the XML structure into an HTML one. To accomplish this task, first we need to link an XSLT stylesheet to our document:

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet href="../xsl/style-1.xsl" type="text/xsl"?>

Then we need to define our stylesheet:

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

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


 <xsl:output method="html"
 doctype-public="-//W3C//DTD HTML 4.01//EN" 
 doctype-system="http://www.w3.org/TR/html4/strict.dtd"/>
 
 
 <xsl:template match="/">
 
  <html>
  
   <head>
    <title>XML Blog</title>
   </head>
   
   <body>
   
    <xsl:apply-templates />
   </body>
  </html>
 
 
 </xsl:template>
 
 <xsl:template match="page">
 
  <div id="page">
  
   <xsl:apply-templates/>
  </div>
 
 
 </xsl:template>
 
 <xsl:template match="headerimg">
 
  <div id="headerimg">
  
   <xsl:apply-templates/>
  
  </div>
 
 
 </xsl:template>
 
 <xsl:template match="h1">
 
  <h1>
   <xsl:value-of select="."/>
  </h1>
 
 
 </xsl:template>
 
 <xsl:template match="description">
 
  <div class="description">
   <xsl:value-of select="."/>
  </div>
 
 
 </xsl:template>
 
 <xsl:template match="content">
 
  <div id="content">
   <xsl:apply-templates />
  </div>
 </xsl:template>
 
 <xsl:template match="post">
 
  <div class="post">
   <xsl:apply-templates/>
  </div>
 </xsl:template>
 
 <xsl:template match="h2">
  <h2>
   <xsl:value-of select="."/>
  </h2>
 </xsl:template>
 
 <xsl:template match="date">
  <small>
   <xsl:value-of select="."/>
  </small>
 </xsl:template>
 
 <xsl:template match="entry">
  <div class="entry">
   <xsl:apply-templates/>
  </div>
 </xsl:template>
 
 <xsl:template match="p">
 
  <p>
   <xsl:value-of select="."/>
  </p>
 
 
 </xsl:template>
 
 <xsl:template match="postmetadata">
 
  <p class="postmetadata">
  
   
   <xsl:apply-templates />
  </p>
 
 
 </xsl:template>
 
 <xsl:template match="link">
  <a href="{@url}">
   <xsl:value-of select="."/>
  </a>
 </xsl:template>
 
 <xsl:template match="sidebar">
 
  <div id="sidebar">
   <form action="#" method="get" id="searchform">
    <div>
     <input type="text" name="s" id="s" />
     <input type="submit" name="searchsubmit" id="searchsubmit" value="Search" />
    </div>
   </form>
   
   <xsl:apply-templates/>
  </div>
 
 </xsl:template>
 
 <xsl:template match="ulist">
 
  <ul>
   <xsl:for-each select="item">
    <li>
     <xsl:apply-templates/>
    </li>
   </xsl:for-each>
  </ul>
 
 </xsl:template>
 
 <xsl:template match="footer">
 
  <div id="footer">
  
   <xsl:apply-templates />
  </div>
 
 </xsl:template>
 
</xsl:stylesheet>

As you can see here, our blog begins to take shape. By turning the XML structure into an HTML one, we can now add some CSS styles to our document. Our CSS file would look like this:

/* General styles */

body {
 margin: 0;
 padding: 0;
 background: #fff;
 color: #333;
 font: 76% Verdana, sans-serif;
}

a:link, a:visited {
 color: #0a0;
}
a:hover {
 color: #393;
}

p, li {
 line-height: 1.5;
}

h1, h2 {
 font-family: "Trebuchet MS", Trebuchet, sans-serif;
 color: #0a0;
}

/* Structure */

#page {
 width: 85%;
 margin: 0 auto;
 padding: 2em 0;
}

#headerimg {
 width: 100%;
 height: 8.3em;
 min-height: 100px;
 background: transparent url("../img/header.png") repeat-x 0 0;
}
#headerimg h1 {
 margin: 0;
 padding: 8px 5px 5px 0;
 text-align: center;
 font-size: 3.5em;
}
#headerimg .description {
 padding: 0 5px 5px 0;
 text-align: center;
 font-style: italic;
 color: #393;
}

#content {
 width: 70%;
 float: right;
}

#sidebar {
 width: 29%;
 float: left;
 padding-bottom: 120px;
 background: transparent url("../img/sidebar.png") no-repeat 0 100%;
}

.post {
 width: 90%;
 margin: 0 auto;
}
.post h2 {
 margin: 0 0 0.2em 0;
 font-size: 1.6em;
 padding-bottom: 2px;
 padding-top: 6px;
 border-bottom: 1px dashed;
 background: transparent url("../img/h2.png") no-repeat 100% 50%;
}
.post small {
 display: block;
 padding: 0.2em;
 background: #efc;
}

.entry {
 width: 100%;
}

.entry .postmetadata {
 border-top: 1px dashed #393;
 border-bottom: 1px dashed #393;
 padding: 0.2em 0;
}

#searchform {
 margin: 0;
 padding-top: 9px;
 width: 100%;
}
 
#searchform #s {
 width: 100px;
 border: 1px solid #393;
 background: #fff;
 margin-right: 0.3em;
}

#searchform #searchsubmit {
 background: #393;
 font-weight: bold;
 color: #fff;
}

#sidebar h2 {
 margin: 7px 0;
 padding: 3px;
 background: #393;
 color: #fff;
}

#sidebar ul {
 margin: 5px 0;
 padding: 0 0 0 3px;
 list-style: none;
}

#sidebar li {
 padding-bottom: 3px;
 padding-left: 1.3em; 
 margin-bottom: 0.3em;
 border-bottom: 1px dashed #393;
 background: transparent url("../img/li.png") no-repeat 0 0.3em;
}
#sidebar li:hover {
 background-image: url("../img/lihover.png");
}

#footer {
 clear: both;
 width: 100%;
 background: #efc;
 padding: 2em 0;
 text-align: center;
 color: #393;
}

In order to attach our CSS file to the XML document, we need to modify our XSLT stylesheet like so:

<xsl:template match="/">
 
  <html>
  
   <head>
    <title>XML Blog</title>
    <link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" />
   </head>
   
   <body>
   
    <xsl:apply-templates />
   </body>
  </html>
 
 
 </xsl:template>

In the code above, we've inserted a link element in the main xsl:template element. Now our XML document will be stylized according to the CSS rules specified earlier in the post. You can see the final result here.

Building a web site with XML

Building a web site with XML was actually the topic of my latest seminar in Milan (SMAU 2009). During this seminar many people asked me some questions that made me think about the effective reliability of such a solution. Here are some topics:

  1. Browser support

    Versions 6, 7 and 8 of Internet Explorer support XML rendering only when the latest version of MSXML is installed and configured. In other words, these versions of IE don't have a native support for XML. What's more, the rendering of CSS styles is quite inconsistent. Check out some of my tests on this subject at CSS Zibaldone.

  2. Validation and DTDs

    Some people asked me how they could validate their XML documents. Basically, you can do this either with a custom DTD or with an XML Schema. It depends a good deal on the dimensions of your web site and the number of elements and attributes you want to use. Personally I like to write my own DTDs, but sometimes I use some XML Schemas, because this solution is faster and it doesn't force you to learn another syntax or grammar (XML Schemas are basically XML).

  3. Element names

    Coming to XML element names, it's always a good choice to use semantic element names, such as branding, content-sub and the like (see Andy Clarke's thoughts on the subject), and avoid presentational names such as header or sidebar.

  4. Using XSLT

    For the final rendering of our document structure, the preferred choice is using XSLT. By doing so, you can serve your structure as XHTML and prevent some browser inconsistencies from happening. For example, if you want to use hyperlinks in your documents, using XLink is not the best solution, because the current browser support is really poor.

  5. Accessibility

    Theoretically speaking, if you use XSLT to transform your XML structure into XHTML, browsers should treat your documents accordingly, and recognize your XML elements as XHTML elements. Anyway, I didn't test it with a screen reader, so you should always run some tests before using this solution. If not, screen readers will probably not recognize your elements and some serious accessibility problems will arise.

XSLT and RSS: test results

I started my tests by stylizing a static RSS file with CSS after transforming it with XSLT and linking to the page through the link element. Browsers apply in this case their own custom template to the RSS file and display it accordingly, so there's no way to circumvent browser default formatting for an RSS document (static in this case). I need more time in order to use a server-side XSLT processing for displaying an RSS document generated on the fly. Time will tell.