cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1108
Views
5
Helpful
4
Replies

Counting entries in a list

Hi,

 

I'm working on a service that provisions prefix lists for customer services. The prefix-lists are of variable sizes and due to that, I want to know the number of entries in my (yang-) list when running my template.

 

In my template, the last entry will be treated differently than the previous and I need a hint how to do this. (In IOS-XR the every prefix-set entry is ended with a comma, except for the last one).

 

TIA.

 

/Johnny

4 Replies 4

vleijon
Cisco Employee
Cisco Employee
In XPath you have access to a number of built-in functions, in particular you have access to count(), which counts the number of nodes in a list and position() which gives the current index. Hopefully you can use a combination of those to achieve the result you want.

I would like to take this opportunity to mention that you can troubleshoot this kind of thing by doing commit | debug xpath, which gives insight into what is happening.

Without testing it I would assume that the NED handles the comma part automatically? Sounds like something that the NED should be handling.. 

 

 

I’m using the example NED in the free trial edition, which seem to be quite limited.

It throws a fault if the comma isn’t present.

Also, it doesn’t do very well if I do updates to the prefix-set. NSO attempts to negate outdated entries, while XR requires a complete re-configuration of the prefix-set. I had hoped that “tags=‘replace’” would’ve solved this, but no luck 😐

Thanks, the count() function gave me the value I needed.

I did not try the position() function, but used a traditional counter variable in the loop.