0

I understand that the "when" statement in a Yang model takes an XPATH expression as its argument.

What is the correct YANG XPATH syntax to combine multiple expressions in order to model a type/value data container as follows ?

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;
    }   
}
predi
  • 5,528
  • 32
  • 60
Mukesh MV
  • 61
  • 1
  • 5

2 Answers2

4

The XPath syntax you used is correct. The only thing you are missing are semicolons after the when statement.

For the complete reference to the XPath syntax used in YANG check XPath 1.0 specification.

6.4. XPath Evaluations

YANG relies on XML Path Language (XPath) 1.0 [XPATH] as a notation for specifying many inter-node references and dependencies.

Community
  • 1
  • 1
Piotr Babij
  • 837
  • 5
  • 12
2

In XPath, the first condition can be written as follow :

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

Or if you're required to explicitly return a boolean type :

when "boolean(../attrib-type[.=1 or .=2])"
har07
  • 88,338
  • 12
  • 84
  • 137