HTML Table DTD

The DTD or document type definition provides a formal definition of the allowed syntax for html tables.

<!-- The HTML Table DTD -->

<!-- border styles   (overridden by style sheets)

        none    suppress borders - useful with graphics etc.
        frame   outer border around table only
        basic   border between thead/tbody and tbody/tfoot
        rows    as per basic plus frame plus row separators
        cols    as per basic plus frame plus column separators
        all     draw borders around all cells
-->

<!ENTITY % border.styles
        "none | frame | basic | rows | cols | all">
        
<!-- horizontal alignment attributes for cell contents -->

<!ENTITY % cell.halign
        "align  (left|center|right|justify|char)        #IMPLIED
         char   CDATA  #IMPLIED  -- alignment char, e.g. align=':' --
         charoff  CDATA  #IMPLIED -- offset of alignment char, eg charoff='50%' --"
        >

<!-- vertical alignment attributes for cell contents -->

<!ENTITY % cell.valign
        "valign  (top|middle|bottom)   #IMPLIED"
        >
        
<!--
%body.content allows table cells to contain headers, paras,
lists, form elements and even arbitrarily nested tables.

%text is text characters, including character entities and
character emphasis elements, IMG and anchors
-->
        
<!ELEMENT table - - (caption?, (colw|hspec|vspec)*, thead?, tbody, tfoot?)>
<!ELEMENT caption - O (%text)+>
<!ELEMENT colw - O EMPTY>
<!ELEMENT hspec - O EMPTY>
<!ELEMENT vspec - O EMPTY>
<!ELEMENT thead - O tr+>
<!ELEMENT tbody O O tr+>
<!ELEMENT tfoot - O tr+>
<!ELEMENT tr - O (th|td)+>
<!ELEMENT (th|td) - O %body.content>

<!ATTLIST table
        width   CDATA   #IMPLIED        -- table width relative to window --
        cols    NUMBER  #IMPLIED        -- used for immediate display mode --
        border  (%border.styles) #IMPLIED  -- see above definition --
        nowrap  (nowrap)  #IMPLIED  -- disable word wrap inside table --
        >

<!ATTLIST caption
        align   (top|bottom)    #IMPLIED        -- relative to table --
        >

<!ATTLIST colw               -- specifies relative column widths --
        col    CDATA  #REQUIRED -- column number or range --
        width  CDATA  #REQUIRED -- positive number, e.g. 2.5 --
        >

<!-- hspec and vspec elements specify alignment properties
for table cells and act like IF-THEN rules. The IF part is
a conjunction of the following optional parts:

        a)      whether the cell is in thead, tbody or tfoot (rowgroup)
        b)      the class attribute of the current row (rowclass)
        c)      whether the cell is a header or data cell (celltype)
        d)      the class attribute of the cell itself (cellclass)
        e)      the cell's row and/or column number (row or col)

If the cell straddles two or more rows or columns, the number
of the first row/column is used for evaluating the match.

The THEN part sets the horizontal or vertical alignment for
the cell's contents. The class attribute of the hspec or tspec
element matching a cell can also be used by style sheets to
attach additional rending properties to groups of cells.

Conflict resolution is real simple:

        a)      properties defined as attributes on cells always
                override hspec or vspec
                
        b)      hspec and vspec are lexically ordered from general
                to specific, i.e. the last matching hspec or vspec
                elements sets the cell's alignment properties
-->

<!ATTLIST hspec
        rowgroup  (thead|tbody|tfoot) #IMPLIED  -- enclosing row group --
        rowclass  CDATA  #IMPLIED  -- class of enclosing row --
        celltype  (th|td)       #IMPLIED        -- header, data or either --
        cellclass CDATA  #IMPLIED  -- class of cell itself --
        %cell.halign;   -- implied horizontal alignment --
        >

<!ATTLIST vspec
        rowgroup  (thead|tbody|tfoot) #IMPLIED  -- enclosing row group --
        rowclass  CDATA  #IMPLIED  -- class of enclosing row --
        celltype  (th|td)       #IMPLIED        -- header, data or either --
        cellclass CDATA  #IMPLIED  -- class of cell itself --
        %cell.valign;
        >
        
<!ATTLIST tr -- table row --
        class   CDATA   #IMPLIED>

<!ATTLIST (th|td)    -- header or data cell --
        class   CDATA   #IMPLIED>
        %cell.halign;   -- horizontal alignment --
        %cell.valign;   -- vertical alignment --
        axis  CDATA  #IMPLIED   -- defaults to cell content --
        axes  CDATA  #IMPLIED   -- list of axis names --
        >