W3C home > Mailing lists > Public > www-forms@w3.org > November 2006

Repeating structures...are they actually special at all?

From: Mark Birbeck <mark.birbeck@x-port.net>
Date: Mon, 20 Nov 2006 19:14:09 +0000
Message-ID: <640dd5060611201114x7fdb3efawabe8197f0529ad94@mail.gmail.com>
To: www-forms <www-forms@w3.org>

Hello all,

In one of our discussions around insert and delete we agreed with
Erik's idea that if @nodeset returns a collection of nodes then we
should process all of them, rather than acting on the first one (the
so-called "first node rule"). I like this, and to me it makes code
easier to read; I can tell what an author has in mind if I see this:

  <delete nodeset="customers/customer[1]" ... />

rather than this:

  <delete nodeset="customers/customer" ... />

Now, after we did this it made me wonder about other situations where
processing the entire nodeset might give rise to different behaviour
if there was more than one node, and one that leapt out was
differentiating between repeating structures and non-repeating
structures simply by the number of nodes in the nodeset. For example,
if there is only one customer in the instance data, then this (if it
were legal):

  <group nodeset="customers/customer">
    <output ref="name" />
    <output ref="telephone" />
  </group>

would behave the same as this:

  <group ref="customers/customer">
    <output ref="name" />
    <output ref="telephone" />
  </group>

If there was more than one customer, then it would be equivalent to a repeat:

  <repeat nodeset="customers/customer">
    <output ref="name" />
    <output ref="telephone" />
  </repeat>

But since the second case (multiple customers) includes the first case
(only one customer) why bother ever using anything other than a
repeating structure? If you don't want a repeat, simply add "[1]" as
we saw before.

Of course the problem would be that using a 'repeat' element when you
don't actually want a repeating structure would be awkward to read:

  <repeat nodeset="customers/customer[1]">
    <output ref="name" />
    <output ref="telephone" />
  </repeat>

or:

  <repeat nodeset="customers[1]">
    <repeat nodeset="customer">
      <output ref="name" />
      <output ref="telephone" />
    </repeat>
  </repeat>

But it's not so the other way round; i.e., saying that elements that
use nodesets operate over all of the nodes in the nodeset is actually
fairly intuitive, which leads me to wondering whether we should allow
this:

  <group nodeset="customers/customer">
    <output ref="name" />
    <output ref="telephone" />
  </group>

in *addition* to this:

  <group ref="customers/customer">
    <output ref="name" />
    <output ref="telephone" />
  </group>

and this:

  <group ref="customers">
    <group nodeset="customer">
      <output ref="name" />
      <output ref="telephone" />
    </group>
  </group>

We would obviously keep the @ref format for backwards compatibility,
and as a shorthand for selecting the first node. But it could could
also be used to set context, if used in conjunction with @nodeset. For
example:

  <group ref="customers" nodeset="customer">
    <output ref="name" />
    <output ref="telephone" />
  </group>

I'm not suggesting that this is a priority to resolve, but I thought
it an interesting one to ponder. (And as a by-product, having both
@ref and @nodeset on elements gets us out of a couple of other sticky
situations, which I'll leave to another time.)

Regards,

Mark

-- 
Mark Birbeck
CEO
x-port.net Ltd.

e: Mark.Birbeck@x-port.net
t: +44 (0) 20 7689 9232
w: http://www.formsPlayer.com/
b: http://internet-apps.blogspot.com/

Download our XForms processor from
http://www.formsPlayer.com/
Received on Monday, 20 November 2006 19:14:43 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 10 March 2012 06:22:08 GMT