RE: Binding to nodes that do not exist

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 UTC