05-11-2025 05:36 PM
I'd like to use xpath eval or a similar Cisco NSO CLI command to further pre-validate my XML code before running "packages reload". I'd like to speed up my template development by catching syntax issues earlier. In particular, I'd like to be able to include conditionals and other commands applied against the xpath on the CLI to try them out before including them in the template. Some examples below for foreach and set that fail. Is this possible with 'xpath eval'? Is there another approach I should take?
ncs(config)# xpath eval /oc-if-config:oc-interfaces//device[device='se1']/interfaces/*
/oc-if-config:oc-interfaces/device[device='se1']/interfaces/interface[name='1/1/c1']
/oc-if-config:oc-interfaces/device[device='se1']/interfaces/interface[name='1/1/c1/1']
/oc-if-config:oc-interfaces/device[device='se1']/interfaces/interface[name='1/1/c2']
/oc-if-config:oc-interfaces/device[device='se1']/interfaces/interface[name='1/1/c2/1']
/oc-if-config:oc-interfaces/device[device='se1']/interfaces/interface[name='1/1/c3']
/oc-if-config:oc-interfaces/device[device='se1']/interfaces/interface[name='1/1/c3/1']
/oc-if-config:oc-interfaces/device[device='se1']/interfaces/interface[name='1/1/c4']
/oc-if-config:oc-interfaces/device[device='se1']/interfaces/interface[name='1/1/c4/1']
/oc-if-config:oc-interfaces/device[device='se1']/interfaces/interface[name='1/1/c5']
/oc-if-config:oc-interfaces/device[device='se1']/interfaces/interface[name='1/1/c6']
/oc-if-config:oc-interfaces/device[device='se1']/interfaces/interface[name='lag-1']
ncs(config)# xpath eval foreach /oc-if-config:oc-interfaces//device[device='se1']/interfaces/*
ncs(config)# xpath eval foreach {/oc-if-config:oc-interfaces//device[device='se1']/interfaces/*}
Error: Invalid name: {/oc-i
ncs(config)#
ncs(config)# xpath eval set INT_LIST=/oc-if-config:oc-interfaces//device[device='se1']/interfaces/*
ncs(config)# xpath eval INT_LIST
ncs(config)#
09-09-2025 02:22 AM
Hi, it seems like you have a mistake in your path with "//" in the xpath eval foreach /oc-if-config:oc-interfaces//device[device='se1']/interfaces/*, but also the point of xpath eval foreach is to execute another xpath expression at the end foreach of the lines matching, see below:
admin@ncs(config)# xpath eval /ncs:devices/device[name='ios0']/config/ios:interface/*
/devices/device[name='ios0']/config/ios:interface/Loopback[name='0']
/devices/device[name='ios0']/config/ios:interface/Port-channel-subinterface
/devices/device[name='ios0']/config/ios:interface/MFR-subinterface
/devices/device[name='ios0']/config/ios:interface/Ethernet[name='0/0/0']
/devices/device[name='ios0']/config/ios:interface/FastEthernet[name='0']
/devices/device[name='ios0']/config/ios:interface/FastEthernet[name='0/0']
/devices/device[name='ios0']/config/ios:interface/FastEthernet[name='1/0']
/devices/device[name='ios0']/config/ios:interface/FastEthernet[name='1/1']
/devices/device[name='ios0']/config/ios:interface/GigabitEthernet[name='0']
/devices/device[name='ios0']/config/ios:interface/GigabitEthernet[name='0/0']
/devices/device[name='ios0']/config/ios:interface/GigabitEthernet[name='0/1']
/devices/device[name='ios0']/config/ios:interface/GigabitEthernet[name='0/2']
/devices/device[name='ios0']/config/ios:interface/Bundle-subinterface
/devices/device[name='ios0']/config/ios:interface/Serial-subinterface
/devices/device[name='ios0']/config/ios:interface/LISP-subinterface
/devices/device[name='ios0']/config/ios:interface/GMPLS-subinterface
admin@ncs(config)# xpath eval foreach /ncs:devices/device[name='ios0']/config/ios:interface/* ?
Possible completions:
<xpath expression>
Inside the templates, you can set context and for loop on the location, if the template needs tweaking, use | debug template for the commit dry-run to find out what is going on in the evaluation of the xpaths.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide