[x]html head semantics question

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

How does the order of title, base and other elements in the
head of a document affect meaning?

I'm working on a Haskell library of combinators to produce
html (currently xhtml1-strict, as that's a little easier),
that ensures confomance to the dtd by typechecking at
compile time. For the most part, the combinators hide the
internal datastructure, reducing clutter.

One part of the DTD is causing me pain.
<!ELEMENT head (%head.misc;,
     ((title, %head.misc;, (base, %head.misc;)?) |
      (base, %head.misc;, (title, %head.misc;))))>

which is a sequence of %head.misc elements with exactly one
title and at most one base interposed. Obviously from a
human author of xhtml's point of view the flexibility in
order is valuable, but a datastructure that represents the
whole flexibility is unwieldy.  If I could fix the order to
be say: %head.misc;, (base)?, title, or title, (base)?,
head.misc; the mandatory aspect of the presence of title
would be less onerous to the eventual user.

I'm aware that for example, head elements specifying charset
might need to appear before title (though that's academic as
the generated html uses character entity references for
anything outside ASCII). Is there anything that cannot be
expressed if the title is forced to appear at the end?

Jón Fairbairn                                 Jon.Fairbairn@cl.cam.ac.uk

Re: [x]html head semantics question

On Tue, 6 Nov 2007, Jon Fairbairn wrote:

Quoted text here. Click to load it

The charset parameter is part of the content-type and therefore
set in the HTTP header.

In memoriam Alan J. Flavell

Re: [x]html head semantics question

Quoted text here. Click to load it

Very little, for elements of different types - I'm not aware of any
issues there. Elements of the same type, there can be an ordering issue
(e.g. stylesheets and selectors with the same specificity)
Quoted text here. Click to load it

I'd say that it'd be easier - given that the <head> element doesn't
have much variety in it - to represent <head> with a different data
type to those used for the sub-elements of <body>.

My structure for developing HTML documents programmatically (not in
Haskell, but I think it would work there in a similar way) is:

        -> Doctype
        -> HTTP headers
        -> Head
                -> Title
                -> Metadata (key-value Dict for <meta>)
                -> [Links] (<link rel="anything other than stylesheet">)
                -> [Stylesheets]
                -> [Scripts]
        -> Body
                -> Tree of elements (HTML and anonymous)

While the 'Body' is a proper tree representation of the HTML (with
constraints), I didn't see the point of doing the same for the Head
(or the small amount of the output document that isn't in either), so
'show Document' just prints out the document and head in that fixed
order before recursively printing the body.

The ones using lists are (or at least could be) sensitive to the order
they appear. The Metadata might be - but probably not consistently
between user-agents - if I allowed multiple ones with the same key, so
I don't. I miss out <base> entirely just because I've not needed it
(and no-one else has asked for it). I expect I'll add it at some


Re: html head semantics question

Quoted text here. Click to load it

Absolutely none. Generate in any order you like. For a user agent to
require any particular order would be wrong.

In practice, both of these are observed.

Quoted text here. Click to load it

Agreed. Andreas merely has an obsession with this. I'm sure that
people coding in Haskell don't need to be reminded.

Site Timeline