[j-nsp] understanding the root container element of node-set in SLAX

Phil Shafer phil at juniper.net
Fri Feb 2 14:53:33 EST 2018


Martin T writes:
>for-each ($results/abc) {
>    <output> name(.);
>}
>
>..then "abc" is printed while I would expect "klm". Is this RTF
>container-element also named "abc"? However, for example,
>"$results/abc/abc" does not match anything.

"for-each" whiffles thru the list of elements that have the name
"abc", so "name(.)" ("the name of the current context node") will
always be "abc".  Since there are no "abc" elements under "abc",
"abc/abc" won't match anything.

I always tell folks to read Xpaths from the end element, so "a/b/c"
means 'any element named "c" parented by any element named "b"
parented by any element named "a" parented by the current context'.
Or "d[x==1]/e[y==2]" is 'any element named "e" that has an "y"
element that is equal to 2, which is parented by an element named
"d" which have an element named "x" which is equal to 1'.

Thanks,
 Phil


More information about the juniper-nsp mailing list