简体   繁体   English

YANG模型“何时”声明用法

[英]YANG model “when” statement usage

I understand that the "when" statement in a Yang model takes an XPATH expression as its argument. 我了解到,Yang模型中的“ when”语句将XPATH表达式作为其参数。

What is the correct YANG XPATH syntax to combine multiple expressions in order to model a type/value data container as follows ? 组合多个表达式以便按如下方式对类型/值数据容器建模的正确YANG XPATH语法是什么?

container c1 {
    leaf  attrib-type {
        type uint32;
    }
    leaf attrib-val-int {
        when "../attrib-type = 1 or ../attrib-type = 2"
        type uint32;
    }   

    leaf attrib-val-string {
        when "../attrib-type = 5 or ../attrib-type = 6"
        type string;
    }   
}

The XPath syntax you used is correct. 您使用的XPath语法正确。 The only thing you are missing are semicolons after the when statement. 您唯一缺少的是when语句后的分号。

For the complete reference to the XPath syntax used in YANG check XPath 1.0 specification. 有关YANG中使用的XPath语法的完整参考,请查看XPath 1.0规范。

6.4. 6.4。 XPath Evaluations XPath评估

YANG relies on XML Path Language (XPath) 1.0 [ XPATH ] as a notation for specifying many inter-node references and dependencies. YANG依赖XML路径语言(XPath)1.0 [ XPATH ]来指定许多节点间引用和依赖关系。

In XPath, the first condition can be written as follow : 在XPath中,第一个条件可以写为:

when "../attrib-type[.=1 or .=2]"

Or if you're required to explicitly return a boolean type : 或者,如果您需要显式返回布尔类型:

when "boolean(../attrib-type[.=1 or .=2])"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM