Search code examples
ietf-netmod-yang

usage of current vs ../ in yang xpath expressions


is the usage of .. and current() in the following snippet correct ? Meaning, there are times when current() and ../ are equivalent ?

container c {
   leaf f1 {
       type string;
   }

   leaf f2 {
      type string;
      when "../f1 = 'abc'";
   }

   leaf f3 {
      type string;
      when "current()/../f1 = 'abc'";
   }
}

Solution

  • The way you use current() in your example is correct, but redundant. current() returns the initial context node and since all expressions start with the initial context node in their contexts in makes no sense to explicitly state this.

    This does not mean that current() is equivalent to ../ at the beginning of an expression. The latter may be expanded into parent::node()/child::node(), which returns all children of the parent of the initial context node. The returning node set will contain the initial context node, along with all its siblings. This is not what current() returns - it is at best similar.

    What would be equivalent is . or, written alternatively, self::node(). If an expression starts with ., it may return the same node as current(), but this is entirely dependent on the context where . is used.