The Scheherazade Problem

There is one complication to the structure of div that is worth knowing about. We said above that a div may consist either of a series of paragraphs and other chunk-level elements, or a series of div elements. In addition, a div may consist of a series of paragraphs followed by one or more div elements. This is a familiar structure, for instance in the case of a report whose sections begin with a few introductory paragraphs followed by several subsections. However, once you have had one div element, you cannot go back to having paragraphs. In other words, divs may follow paragraphs, but they may not be interspersed with paragraphs.

In the examples below, the first illustrates an invalid encoding in which the main div element contains a series of paragraphs, followed by a subdivision, and then more paragraphs. The example is an instance of the classic Scheherazade Problem, in which a framing narrative is punctuated by a series of self-contained stories, each of which has some internal structure (for instance, a heading, internal subdivisions, etc.). The boundaries of the embedded stories may be made even clearer by the book’s typography: for instance, each story may be printed in a smaller type, with larger margins than the enclosing narrative, or it might even be in a different language. Such factors would make it very desirable to mark the boundaries of these embedded narratives explicitly. However, div cannot be used here. The encoding of Example 1 is invalid, although it is tempting precisely because it represents with complete accuracy what is really going on.

The best alternative is to encode each nested narrative as a separate text element, as shown in Example 2. The text element must be embedded within a p, q, or quote element. The choice depends on whether the embedded narrative is being quoted from outside the text (use quote), narrated by a speaker from within the text (use q) or simply embedded (use p). This approach gives greater individual weight to each embedded story, rather than treating it as a subdivision of the main narrative line.

Another, simpler approach, is to encode each embedded narrative as an extended quote element (if it is being quoted from outside the text: for instance, a trial document or letter) or q element (if the story is being narrated by someone from within the main narrative). This approach will only be manageable for short, simple inclusions with no internal structure; the quote element cannot accommodate features like headings or internal subdivisions, so if these features are present, you will need to use text.

A third valid encoding, using div, is shown in example 3, where the enclosing narrative is itself subdivided so that each of its intervening parts is encoded as a separate div. The disadvantage of this approach is that it misrepresents the textual structure: the enclosing narrative does not actually consist of separate blobs of text, but rather one continuous flow interrupted by the embedded stories. An improvement is Example 4, which shows the same encoding, but with the next and prev attributes used to indicate that the enclosing narrative is a single textual stream.

Examples

Example 1

<div>
  <head>Fireside Stories</head>

  <p>After dinner the family gathered around the fire for their usual
  round of story-telling. Uncle Peter volunteered to begin. Everyone
  groaned, expecting a repetition of his usual tedious tale about the
  day he had caught the big fish that got away. But this evening he
  surprised everyone...
  </p>
  <div>
    <head>Uncle Peter’s Surprising Story</head>
    <p>I was born on the day when the river flooded...</p>
    [more of Uncle Peter’s fascinating story]
  </div>
  <p>When Uncle Peter was done, everyone sat back and laughed
  heartily. The unexpected twist at the end had caught them unawares
  and their relief was palpable. Aunt Hannah finally wiped her eyes
  with her apron and said that she had a story quite closely connected
  to his. At this everyone settled down once again with great
  interest.
  </p>
  <div>
    <head>Aunt Hannah’s Delightful Account</head>
    <p>I, too, was born on the day when the river flooded...</p>
    [more of Aunt Hannah’s interminable narrative]
  </div>
  <p>By the end, everyone was breathless with suppressed mirth, except
  for Uncle Peter, who had fallen asleep in his chair.</p>
</div>

Example 2: The recommended approach, using text

<div>
  <head>Fireside Stories</head>

  <p>After dinner the family gathered around the fire for their usual
  round of story-telling. Uncle Peter volunteered to begin. Everyone
  groaned, expecting a repetition of his usual tedious tale about the
  day he had caught the big fish that got away. But this evening he
  surprised everyone...
  </p>
  <q>
  <text>
    <body>    
      <head>Uncle Peter’s Surprising Story</head>
      <p>I was born on the day when the river flooded...</p>
      [more of Uncle Peter’s fascinating story]
    </body>
  </text>
  </q>
  <p>When Uncle Peter was done, everyone sat back and laughed
  heartily. The unexpected twist at the end had caught them unawares
  and their relief was palpable. Aunt Hannah finally wiped her eyes
  with her apron and said that she had a story quite closely connected
  to his. At this everyone settled down once again with great
  interest.
  </p>
  <q>
  <text>
    <body>
      <head>Aunt Hannah’s Delightful Account</head>
      <p>I, too, was born on the day when the river flooded...</p>
      [more of Aunt Hannah’s interminable narrative]
    </body>
  </text>
  </q>
  <p>By the end, everyone was breathless with suppressed mirth, except
  for Uncle Peter, who had fallen asleep in his chair.</p>
</div>

Example 3: A valid version using div

<div>
  <head>Fireside Stories</head>
  <div>
  <p>After dinner the family gathered around the fire for their usual
  round of story-telling. Uncle Peter volunteered to begin. Everyone
  groaned, expecting a repetition of his usual tedious tale about the
  day he had caught the big fish that got away. But this evening he
  surprised everyone...
  </p>
  </div>
  <div>
    <head>Uncle Peter’s Surprising Story</head>
    <p>I was born on the day when the river flooded...</p>
    [more of Uncle Peter’s fascinating story]
  </div>
  <div>
  <p>When Uncle Peter was done, everyone sat back and laughed
  heartily. The unexpected twist at the end had caught them unawares
  and their relief was palpable. Aunt Hannah finally wiped her eyes
  with her apron and said that she had a story quite closely connected
  to his. At this everyone settled down once again with great
  interest.
  </p>
  </div>
  <div>
    <head>Aunt Hannah’s Delightful Account</head>
    <p>I, too, was born on the day when the river flooded...</p>
    [more of Aunt Hannah’s interminable narrative]
  </div>
  <div>
  <p>By the end, everyone was breathless with suppressed mirth, except
  for Uncle Peter, who had fallen asleep in his chair.</p>
  </div>
</div>

Example 4: A more complex encoding using next and prev

<div>
  <head>Fireside Stories</head>
  <div id="enclosing1" next="enclosing2">
  <p>After dinner the family gathered around the fire for their usual
  round of story-telling. Uncle Peter volunteered to begin. Everyone
  groaned, expecting a repetition of his usual tedious tale about the
  day he had caught the big fish that got away. But this evening he
  surprised everyone...
  </p>
  </div>
  <div>
    <head>Uncle Peter’s Surprising Story</head>
    <p>I was born on the day when the river flooded...</p>
    [more of Uncle Peter’s fascinating story]
  </div>
  <div id="enclosing2" prev="enclosing1" next="enclosing3">
  <p>When Uncle Peter was done, everyone sat back and laughed
  heartily. The unexpected twist at the end had caught them unawares
  and their relief was palpable. Aunt Hannah finally wiped her eyes
  with her apron and said that she had a story quite closely connected
  to his. At this everyone settled down once again with great
  interest.
  </p>
  </div>
  <div>
    <head>Aunt Hannah’s Delightful Account</head>
    <p>I, too, was born on the day when the river flooded...</p>
    [more of Aunt Hannah’s interminable narrative]
  </div>
  <div id="enclosing3" prev="enclosing2">
  <p>By the end, everyone was breathless with suppressed mirth, except
  for Uncle Peter, who had fallen asleep in his chair.</p>
  </div>
</div>