Hi,
I have this must statement which I want to use to check if a leaf-list contains a certain value:
must "contains(route-target, '15525')";
In the xpath trace I see this:
18-Jun-2019::13:38:17.870 evaluating: /vrf:vrf[device='xr-1'][vrf-name='foo']/ipv4/imports: contains(string(route-target), '15525') 18-Jun-2019::13:38:17.871 get_elem(/vrf:vrf[device='xr-1'][vrf-name='foo']/ipv4/imports/route-target) = 12:34 15525:246 23:45 18-Jun-2019::13:38:17.871 result: /vrf:vrf[device='xr-1'][vrf-name='foo']/ipv4/imports: false
I'm trying to figure out if I'm doing something wrong.
As sanity check, I tested this statement:
must "starts-with(route-target, '12:34')";
This one works as expected.
So, for some reason, I'm unable to use the contains function, but some other functions are working as I'd expect.
Any thoughts?
Thanks!
Solved! Go to Solution.
contains() evaluates its argument as strings; route-target is a leaf-list I suppose, i.e. it returns a node-set, and a string evaluation of a node-set is the string value of its first node. You may want something like this instead:
must "route-target[contains(., '15525')]";
contains() evaluates its argument as strings; route-target is a leaf-list I suppose, i.e. it returns a node-set, and a string evaluation of a node-set is the string value of its first node. You may want something like this instead:
must "route-target[contains(., '15525')]";
That did it!
Thank you very much!
Would you mind describing the statement in words?
How come '.' is pointing where it does?
What does the statement returns? A Boolean value? The node itself?
Thanks again!
It returns a node-set which is then converted to boolean - non-empty set to true, empty to false. The result can be described as all instances of route-target
such that .
, the instance itself, as a string contains '15525'.
Thank you for the explanation!