tags:

views:

89

answers:

7

When I hear a list, I expect there will be more than one item.

Is this ever a problem? Am I simply being semantically anal?

<h3>Search Results</h3>
<ul>
    <li><a href="??">only one result</a></li>
</ul>

One child list item element doesn't really seem to be a list does it? Has anyone else ever thought about this too?

+2  A: 

A one-item (or even zero-item) list is perfectly valid. What sort of "problem" do you envision?

Jim Garrison
No real problem per se, just a clash of semantics.
alex
+3  A: 

I think that it is OK to say that a list with just one element is still a list.

You might want to consider the list not just in terms of what it has, but in terms of what it is allowed to have.

Shoko
+2  A: 

What defines a list is its behavior such as [typically]:

  • provide a way to inquire the number o items in the list
  • allows accessing individual items indexing by a numeric subscript
  • allows inserting items in the list
  • ...

Does a "maybe-list" with only one item in it (or even with zero items in it) do all these things just as well as when it has several items ?

I think it does and this answers your question then...

mjv
A: 

A list can have empty, 1 or many elements. In your case,

<!-- empty unordered list -->
<ul>
</ul>

<!-- unordered list contains 1 element -->
<ul>
    <li><a href="??">only one result</a></li>
</ul>
codemeit
+1  A: 

I think of lists the same way I think of sets (a set can be empty, contain only one element, or contain more than one element). If you don't allow sets to contain 1 or 0 elements, you break set arithmetic. For instance, the intersection of two sets should always return a set. Even if that set is a set of one or zero. If you say the intersection of two sets should always return a set, unless that set only contains one element in which case it should return an element, or if it contains zero elements in which case it should return 0. In reality, it is only consistent if sets are allowed to be sets of one or null sets. Same thing with lists. Every list can be expressed as the sum/union of two lists. The null list can be expressed as the union of two null lists. A list containing 2 elements can be expressed as a union of two sets each containing one element. Et "set"era.

Steven Xu
A: 

Both in terms of literal definition and as a data type, a list can have only one element.

(Where would you start from otherwise? :))

Sasha
+3  A: 

0 items is invalid, 1 or more items are valid

But don't take my word for it! The only way to settle this is by running it through W3 Validator service.
I mean, anyone is semantically anal about XHTML, it's gotta be them!

Here's my input:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
   <title>Doc title</title>
   <meta http-equiv="content-type" content="application/xhtml+xml;charset=utf-8" />
   <meta http-equiv="content-style-type" content="text/css" />
 </head>
 <body>
   <div>

    <h3>List with no items</h3>
    <ul>
    </ul>
    <h3>List with one item</h3>
    <ul>
        <li>Only one</li>
    </ul>
    <h3>List with two items</h3>
    <ul>
    <li>One</li>
    <li>Two</li>
    </ul>

   </div>
</body>

</html>

And here's the result:

Validation Output: 1 Error

  1. Error Line 15, Column 5: end tag for "ul" which is not finished

    </ul>

    Most likely, you nested tags and closed them in the wrong order. For example e <p><em>...</p> is not acceptable, as <em> must be closed before <p>. Acceptable nesting is: <p><em>...</em></p>

    Another possibility is that you used an element which requires a child element that you did not include. Hence the parent element is "not finished", not complete. For instance, in HTML the element must contain a child element, lists (ul, ol, dl) require list items (li, or dt, dd), and so on.

The relevant bit here of course is "you used an element which requires a child element that you did not include"

Try it for yourself!

bguiz
The W3C validator checks for **conformance**, not semantic correctness.
Alohci