[j-nsp] understand the index in jcs:break-lines() function in SLAX

Phil Shafer phil at juniper.net
Thu Jan 14 16:12:19 EST 2016


Martin T writes:
>However, script above returns an empty line.

$line is a node-set, but you are making a string out of it.  XPath
specifies that when you turn a node-set into a string, it "is
converted to a string by returning the string-value of the node in
the node-set that is first in document order. If the node-set is
empty, an empty string is returned."

The numbering is "origin 1", so $line[1] is the first element, but
because the output starts with a newline, we know that $line[1]
will be empty.  You can confirm this in the debugger:

    (sdb) p $line
    [node-set] (6)
    <output></output>
    <output>MAC address information:</output>
    <output>  Public base address     00:19:e2:91:e4:00</output>
    <output>  Public count            1008</output>
    <output>  Private base address    00:19:e2:91:e7:f0</output>
    <output>  Private count           16</output>
    
    (sdb) p $line[1]
    [node-set] (1)
    <output></output>
    
    (sdb) p $line[4]
    [node-set] (1)
    <output>  Public count            1008</output>

I ran your script on my mac using "juise -d @my-router your-script.xml"
and stepped thru to line 9.  You get the same debugger using "op
invoke-debugger" under JUNOS.

Thanks,
 Phil


More information about the juniper-nsp mailing list