.
and current()
are not the same in YANG, though they may return the same result in certain situations. The result of .
changes with XPath path steps (the current context node, as you yourself refer to in your code), while current()
always returns the same node no matter where it is used within the same XPath expression - the initial context node.
The initial context node for an XPath expression in YANG depends on where this expression is defined with respect to YANG schema. A combination of rules in RFC7950, Section 6.4.1 and these are used to determine the initial context node:
The XPath expression is conceptually evaluated in the following
context, in addition to the definition in Section 6.4.1:
o If the "when" statement is a child of an "augment" statement, then
the context node is the augment's target node in the data tree, if
the target node is a data node. Otherwise, the context node is
the closest ancestor node to the target node that is also a data
node. If no such node exists, the context node is the root node.
The accessible tree is tentatively altered during the processing
of the XPath expression by removing all instances (if any) of the
nodes added by the "augment" statement.
o If the "when" statement is a child of a "uses", "choice", or
"case" statement, then the context node is the closest ancestor
node to the node with the "when" statement that is also a data
node. If no such node exists, the context node is the root node.
The accessible tree is tentatively altered during the processing
of the XPath expression by removing all instances (if any) of the
nodes added by the "uses", "choice", or "case" statement.
o If the "when" statement is a child of any other data definition
statement, the accessible tree is tentatively altered during the
processing of the XPath expression by replacing all instances of
the data node for which the "when" statement is defined with a
single dummy node with the same name, but with no value and no
children. If no such instance exists, the dummy node is
tentatively created. The context node is this dummy node.
RFC7950, Section 7.21.5
The XPath expression is conceptually evaluated in the following
context, in addition to the definition in Section 6.4.1:
o If the "must" statement is a substatement of a "notification"
statement, the context node is the node representing the
notification in the accessible tree.
o If the "must" statement is a substatement of an "input" statement,
the context node is the node representing the operation in the
accessible tree.
o If the "must" statement is a substatement of an "output"
statement, the context node is the node representing the operation
in the accessible tree.
o Otherwise, the context node is the node in the accessible tree for
which the "must" statement is defined.
RFC7950, Section 7.5.3
The "path" XPath expression is conceptually evaluated in the
following context, in addition to the definition in Section 6.4.1:
o If the "path" statement is defined within a typedef, the context
node is the leaf or leaf-list node in the data tree that
references the typedef.
o Otherwise, the context node is the node in the data tree for which
the "path" statement is defined.
RFC7950, Section 9.9.2
All of these rules need to be implemented in order to support standard YANG XPath, current()
function included.