hcard-example1-steps

From Microformats Wiki
Revision as of 04:59, 15 August 2005 by 67.162.169.209 (talk) (Fixed Spelling)
Jump to navigation Jump to search

hCard Example 1 Steps

This is a step by step explanation of the first example in the hCard specification.

Example

vCard example

Here is a sample vCard:

BEGIN:VCARD
VERSION:3.0
N:Çelik;Tantek
FN:Tantek Çelik
URL:http://tantek.com
ORG:Technorati
END:VCARD

hCard example iteration 0: literal

and an equivalent in literal hCard:

<div class="vcard">
 <a class="url" href="http://tantek.com/">
  <span class="n" style="display:none"> <!-- hide this from display with CSS -->
   <span class="family-name">Çelik</span>
   <span class="given-name">Tantek</span> 
  </span>
  <span class="fn">Tantek Çelik</span>
 </a>
 <div class="org"><span class="organization-name">Technorati</span></div>
</div>

Note that the "N" type, as defined in RFC2426, Section 3.1.2, has several components, and thus these components are defined using nested elements with a class name that is a direct equivalent of the component from the RFC, e.g. "given-name" and "family-name".

Both the vCard and the literal hCard violate the DRY principle by duplicating the name information. The hCard version compensates for this by hiding one occurence with CSS.

hCard example iteration 1: DRY

However, structurally the same XHTML element could be reused for the "N" and "FN" types (since multiple class names can be placed in one class attribute by space separating them), and thus duplication of the name information itself can be eliminated:

<div class="vcard">
 <a class="url" href="http://tantek.com/">
  <span class="fn n">
   <span class="given-name">Tantek</span> 
   <span class="family-name">Çelik</span>
  </span>
 </a>
 <div class="org"><span class="organization-name">Technorati</span></div>
</div>

Thus even with this first iteration we have made a significant improvement over the vCard, by avoiding the repeating of name information, and conforming to the DRY principle.

hCard example iteration 2: element conservation

This can be even further optimized by placing the "fn" and "n" class names on the <a href>, and eliminating the intermediate span.

<div class="vcard">
 <a class="url fn n" href="http://tantek.com/">
  <span class="given-name">Tantek</span> 
  <span class="family-name">Çelik</span>
 </a>
 <div class="org"><span class="organization-name">Technorati</span></div>
</div>

hCard example iteration 3: implied optimizations

Finally, using the Implied "N" Optimization and Implied "organization-name" Optimization, we are able to omit the explicit given and family names markup as well as the explicit "n" and "organization-name".

<div class="vcard">
 <a class="url fn" href="http://tantek.com/">
  Tantek Çelik
 </a>
 <div class="org">Technorati</div>
</div>

hCard display

The display for all versions of this hCard is the same:

Tantek Çelik
Technorati


Back to the hCard specification.