W3C home > Mailing lists > Public > www-forms@w3.org > September 2005

RE: Binding to nodes that do not exist

From: Mark Birbeck <mark.birbeck@x-port.net>
Date: Fri, 9 Sep 2005 11:16:29 +0100
Message-ID: <64B9895D-9AA9-4CF3-9883-7238899DE12C@S009>
To: "'Vincent Berger'" <vincent.berger@afp.com>
Cc: <www-forms@w3.org>, <formsPlayer@yahoogroups.com>

Vince,

> <xf:group ref="if(string-length(name(/path/to/the/node)) > 0, /null, .)">
>  <xf:trigger>
>       <xf:label>
>           Add New
>       </xf:label>
>  </xf:trigger>
> </xf:group>
>
> where /null is a node that never exists.
>
> Itīs not very nice but ... it works.
 
Unfortunately, it shouldn't work :)

The if() function takes parameters of strings, and also returns a string. So
your if() function will straight away fail (or rather, should) since you are
passing in nodes. However, given that most people assume as you have done
that it *should* take and return a node, it's obviously an unnecessary
limitation, and takes nothing to implement in the way you have described. We
raised exactly this issue a little while ago on the XForms WG, after two of
us here made exactly the same mistake as you and were annoyed to find that
it didn't work. The point has been accepted, and the debate is whether to
make a change to the if() function, or to add a new function that is more
general.

One other point is that you don't need the xf:group that you have put in,
since you can just put the @ref straight onto the xf:trigger.

So returning to the original question, if we had a customer node that
contains a list of customers, we could control the xf:trigger like this:

  <xf:group ref="customers">
    <xf:repeat nodeset="customer">
      ...
    </xf:repeat>

    <xf:trigger ref=".[not(*)]">
      <xf:label>Add Item</xf:label>
    </xf:trigger>
  </xf:group>

Rather than trying to manipulate the empty nodeset, we test whether the
parent has any children. In most cases this should work.

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 Friday, 9 September 2005 10:17:07 GMT

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