Does "leaf-list" support count()

Hi,
i wan to use count() and must statement in leaf-list.
does leaf-list support count() ?
( i saw RFC https://tools.ietf.org/html/rfc7950#section-7.7 ) no word about it .
i tried but it dose not work.

It definitely should - in a XPath expression a leaf-list evaluates to a node-set and you can apply count on that. So you can have something like this:

 container parent {
   must "count(leaflist) < 3";
   leaf-list leaflist {
     type string;
   }
 }

Works for me with confd-6.7. But note such statement needs to be written in the context of an ancestor node, it might not be a good idea to write it in the leaf-list itself.

1 Like

Agreed - though of course in this example, and probably in most cases where you might consider using “must with count()” for a leaf-list, it may be clearer to use the min-elements and/or max-elements substatements. I.e.

   must "count(leaflist) < 3";
   leaf-list leaflist {
     type string;
   }

is equivalent to

   leaf-list leaflist {
     type string;
     max-elements 2;
  }

You can’t express things like "count(...) < 3 or count(...) > 5" that way of course, but I would think constraints like that are pretty unusual. Another case that would require “must with count()” is if you want to have a restriction not just on the number of elements, but on the number of elements with some specific property.

1 Like