usage of current vs ../ in yang xpath expressions

♀尐吖头ヾ 提交于 2019-12-31 05:06:47

问题


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'";
   }
}

回答1:


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.



来源:https://stackoverflow.com/questions/41751872/usage-of-current-vs-in-yang-xpath-expressions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!