XPath expressions are used in YANG must and when statements to describe constraints to
related data nodes.
Comparison of values in XPath is complicated and not that intuitive.
It is important to remember that comparison of 2 nodes is done by converting the node-set to a string first.
container mustcontainer {
must "val1 = 0 or val2 = 0 or val1 <= val2" {
error-message "Incorrect values!!";
}
leaf val1 {
type uint32;
units seconds;
}
leaf val2 {
type uint32;
units seconds;
}
}
Yumapro raises error for values val1 = 20 and val2 = 100, though it is a valid combination.
XPath actually compares the string "20" to the string "100" and correctly determines that val1 is greater than val2.
In order to compare node-sets that represent a numeric leaf or leaf-list, make sure to force
XPath to convert the values to numbers for comparison.
Wrong XPath:
must "val1 = 0 or val2 = 0 or val1 <= val2";
Correct XPath:
must "val1 = 0 or val2 = 0 or number(val1) <= number(val2)" ;