On Wed, 2018-03-28 at 16:19 +0000, Sterne, Jason (Nokia - CA/Ottawa) wrote:
> Thx Martin.  Pls see below.
> Jason
> 
> > -----Original Message-----
> > From: Martin Bjorklund [mailto:[email protected]]
> > Sent: Wednesday, March 28, 2018 2:26 AM
> > To: Sterne, Jason (Nokia - CA/Ottawa) <[email protected]>
> > Cc: [email protected]
> > Subject: Re: [netmod] YANG 'must' Xpaths, predicates and wildcards
> > 
> > Hi,
> > 
> > "Sterne, Jason (Nokia - CA/Ottawa)" <[email protected]> wrote:
> > > Hi all,
> > > 
> > > I'm pretty sure that this xpath (e.g. in a must statement) isn't
> > > correct:
> > > 
> > >               (A) ../container-a/list-b[name=*]/some-leaf
> > > 
> > > and should just be this instead:
> > > 
> > >               (B) ../container-a/list-b/some-leaf
> > 
> > Assuming all list entries has a 'name', yes, it is the same.
> > 
> > > Or is the * an allowable wildcard for a key value in a predicate ?
> > 
> > "*" is syntactically legal, 
> 
> [>>JTS: ] That surprises me. I've seen the use of * described in XPath docs
> but it always seems to be in cases outside any predicates.  I couldn't find
> somewhere that shows * as a wildcard in a predicate (or examples of them).
> [>>JTS: ] Does this [xyz=*] work for all types of keys (strings, integers,
> etc) ?  (i.e. will match on all entries in the list)
> 
> but is not a wildcard on all values of the
> > node; it is a wildcard for all nodes.

It really doesn't matter, the asterisk is a special case of location path that
selects all element children of the context node, see 

https://www.w3.org/TR/1999/REC-xpath-19991116/#location-paths

If used in a predicate like [xyz=*], then the rules (quite complex) for equality
expressions have to be taken into account.

Lada

> > 
> > So if all list entries has a name, A will evaluate to the same nodeset
> > as B, since "name = *" is a node-set comparison, and the node "name"
> > will be present in the node set from "*" (node set comparisons are not
> > always intuitive; read the spec for all details ;-)
> 
> [>>JTS: ] I'll try to dig through the specs but this subtlety (wildcard for
> all nodes, vs wildcard for all values) is beyond me at the moment.  
> [>>JTS: ] You mention "if all list entries has a name".  I assume you mean
> that all list-b entries have a name.  I wasn't clear enough above but in my
> example, 'name' is the key for list-b.   So all entries have a name (ignoring
> config false lists that can have no keys for the moment).
> 
> > 
> > > I also had a question about whether the following "must" correctly
> > > checks that at least one entry exists in a-list.
> > > 
> > >   container c1 {
> > >     leaf foo {
> > >       must "a-list";
> > >       type uint16;
> > >     }
> > >     list a-list {
> > >       key "entry";
> > >       leaf entry {
> > >         type uint16;
> > >       }
> > >       leaf another-entry {
> > >         type uint32;
> > >       }
> > >     }
> > >   }
> > > 
> > > I think I could also replace that must with the following:
> > >       must "count(a-list) > 1";
> > > but does must "a-list"; achieve the same thing ?
> > 
> > Yes, but if the list is big, the simple "a-list" may be more
> > efficient, since "count()" will actually count all instances
> > (modulo existance of optimizations in the evaluator).
> > 
> > 
> > /martin
> 
> _______________________________________________
> netmod mailing list
> [email protected]
> https://www.ietf.org/mailman/listinfo/netmod
-- 
Ladislav Lhotka
Head, CZ.NIC Labs
PGP Key ID: 0xB8F92B08A9F76C67

_______________________________________________
netmod mailing list
[email protected]
https://www.ietf.org/mailman/listinfo/netmod

Reply via email to