In a must expression, how do I specify a condition where a given attribute exists? And how about when it does NOT exist?
My understanding is that I can just name the attribute in a must expression to test for its existence and I can wrap them around a not() to test for their non-existence.
For instance, let’s say I have a container C with several leaves inside, among which leaves X and Y are integers.
My condition is that X must exist if Y is > 10. Everything else is allowed.
In the container I would add this:
must “(Y > 10 and X) or Y <= 10 or not(Y)”;
Is the existence test correct? What happens if a leaf takes the value 0? Is that evaluated as False in the logical expression? For instance, if Y=0, does not(Y) test for the non-existence of Y or does it evaluate to not(False)=True ?
Correct - assuming that with “attribute”, you actually mean “leaf”. It gets pretty confusing to use this meaning of the word in the context of XML/XPath, since it has a very different meaning there.
Yes, but your full expression is unnecessarily complex - it is useful to apply some standard rules of logic to avoid overly complex expressions which may be inefficient to evaluate. Another useful thing to know is that any value comparison with a leaf that doesn’t exist (i.e. “an empty node-set”) evaluates to false. I.e. if foo doesn’t exist, both foo < 10 and foo >= 10 are false. Thus your expression can be reduced to:
must "X or not(Y > 10)";
It has no special significance.
XPath in general is incredibly complex IMHO, but you may want to pick up some introductory text or tutorial about it - it’s not a ConfD or even YANG invention:-)