On 07/08/18 18:37, Sterne, Jason (Nokia - CA/Ottawa) wrote:
Hi all,

When comparing the value of a boolean leaf in a 'when' statement (or a 'must' 
statement), is an equality comparison to 'true' or 'false' the same as a check 
against true() or false() ?

For example:

leaf a {
    type boolean;
}
leaf b {
    type uint32;
    when ".../a = 'true'";
}
leaf c {
    type uint32;
    when ".../a = 'false'";
}
(note that neither b nor c can be configured if leaf a isn't explicitly 
configured with a value since there is no default)

If I replace the two 'when' statements above with the following instead, is the 
behavior the same ?
    …
    when ".../a = true()";
    …
    when ".../a = false()";
    …

Or does "../a = true()" behave as an existence check on leaf a and would be 
enabled whether a is configured as true or false ?

Regards,
Jason



See https://www.w3.org/TR/1999/REC-xpath-19991116/#booleans

(a) "../a = 'true'"

Compares 'string-value' (same as value of node if a leaf, rather more 
interesting if a list / container!) of each node in nodeset generated by '../a' 
and if any node in the nodeset matches 'true', expression is true.

(b) "../a = true()"

Similar to above but after getting the string-value, this is converted to a 
boolean before comparing with the boolean true.

(c) '../a'

True if the nodeset generated by this expression is not empty.

---

Caveats alluded to above are that if '../a' matches multiple nodes, then only 
one of these nodes needs to pass the test for the test to be true.  Separately, 
if any of the nodes are not leaves, the 'string-value' is a concatenated string 
of the values of the node's child / grandchild leaves.

Hope that helps.  You wouldn't believe the number of unit tests I have to make 
sure we get this logic right!  Using '!=' when comparing a nodeset with >1 node 
with other values is very likely not to give the answer you expect (-:

Regards,

William


_______________________________________________
netmod mailing list
[email protected]
https://www.ietf.org/mailman/listinfo/netmod

Reply via email to