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

Martin T m4rtntns at gmail.com
Mon Feb 5 05:17:31 EST 2018


On Fri, Feb 2, 2018 at 9:53 PM, Phil Shafer <phil at juniper.net> wrote:
> 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

Phil,

thanks for explaining this! However, let's say that I change the
$results variable to:

var $results = jcs:invoke(<get-software-information>);


When I print the $results variable in debugger, then I can see following:

(sdb) print $results
[node-set] (1)
<software-information>

Now when I set my for-each statement to "for-each
($results/software-information)", then nothing is printed while in the
case of "for-each ($results/abc)" the "abc" was printed. The reason
for this should be that the current context node in already
"software-information" and there are no "software-information"
elements under "software-information".

So am I correct that such manually set node-set variables add simply a
new (unnamed?) root element which needs to be taken into account when
creating XPath statements?


thanks,
Martin


More information about the juniper-nsp mailing list