cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
4438
Views
20
Helpful
10
Replies

List of Xpath Operators

tsiemers1
Spotlight
Spotlight

Does anybody know if the NSO docs contain a section with a list of supported xpath operators (contains, starts-with....)

https://www.tutorialspoint.com/xpath/xpath_operators.htm

 

I looked over the docs and couldn't find anything specific. Running some restconf immediate-queriers and they fail with some operators. Want to verify they are either not supported or my query expression is wrong.

1 Accepted Solution

Accepted Solutions

vleijon
Cisco Employee
Cisco Employee
There is a small section in the tailf_yang_extensions man-page that covers XPath functions that are particular to NSO. I do not think there is a full list in the documentation.

I think this is a complete list of the functions though:


* last
* position
* count
* id
* local-name
* namespace-uri
* name
* string
* concat
* starts-with
* contains
* substring-before
* substring-after
* substring
* string-length
* normalize-space
* translate
* boolean
* nodeset-as-boolean
* false
* true
* not
* number
* sum
* floor
* ceiling
* round
* re-match
* string-compare
* compare
* current
* deref
* sort-by
* enum-value
* bit-is-set
* min
* max
* avg
* band
* bor
* bxor
* bnot





View solution in original post

10 Replies 10

vleijon
Cisco Employee
Cisco Employee
There is a small section in the tailf_yang_extensions man-page that covers XPath functions that are particular to NSO. I do not think there is a full list in the documentation.

I think this is a complete list of the functions though:


* last
* position
* count
* id
* local-name
* namespace-uri
* name
* string
* concat
* starts-with
* contains
* substring-before
* substring-after
* substring
* string-length
* normalize-space
* translate
* boolean
* nodeset-as-boolean
* false
* true
* not
* number
* sum
* floor
* ceiling
* round
* re-match
* string-compare
* compare
* current
* deref
* sort-by
* enum-value
* bit-is-set
* min
* max
* avg
* band
* bor
* bxor
* bnot





Nice. Thats what I was after. Thanks

rogaglia
Cisco Employee
Cisco Employee

Remember that you can evaluate xpath expressions in NSO:

admin@ncs> set devtools true
[ok][2021-07-12 15:37:48]
admin@ncs>config

admin@ncs% xpath eval "10 div 2"
5
[ok][2021-07-12 15:40:30]

[edit]
admin@ncs%

admin@ncs% xpath eval 1=1
true
[ok][2021-07-12 15:38:55]

[edit]
admin@ncs%

admin@ncs% xpath eval ceiling(2.5)
3
[ok][2021-07-12 15:42:01]

[edit]
admin@ncs%

Was not aware of this, very cool.

For information, though I think you might already know too much for this to be useful, I am going to be doing an introduction to XPath at the next NSO Developer Days.

Hello @vleijon,

 

Do you have an update about the introduction to XPath ?
I am really interested in knowing more since documentation on this suject in NCS is very limited and it looks like what one can find on the internet does not cover the whole capacity of XPath in NCS.


Thanks in advance.
Rahenda

 

We are hoping to open registration any day now, and all the information will be posted to this forum.

My session will be on September 15th,, or available in recorded form afterwards of course. The presentation will be fairly short, but I have created an appendix to my slide deck with examples of all the XPath functions being used and I am preparing a few test scripts and examples that people can use on their own to explore this on their own.

@vleijonOk noted, thank you ! I'll keep checking for updates then.

In the meantime,

I am looking for a way to combine XPath filter with tree navigation such as :

/ncs:devices/ncs:device/commit-queue[queue-length!=0 AND ../../device-type/*/ned-id="lsa-netconf"]/queue-length

 

 

As far as I know, the given tutorialspoint link above does not cover such use case. Maybe do you have any idea on how to achieve this ?

Thanks in advance.

That kind of stuff should work, you should use single quotes for strings in XPath and you need to use lowercase, otherwise it looks right to me. One way that makes it a bit easier is to develop is to build it gradually so begin with
/ncs:devices/ncs:device[device-type/*/ned-id=’lsa-netconf’]
And see what results you get, then add on the second condition
/ncs:devices/ncs:device[device-type/*/ned-id=’lsa-netconf’][commit-queue/ueue-length!=0]

Unfortunately I don’t have a suitable system for testing right now, so this is all theory-crafting.