[j-nsp] Conditional statement in XPath predicates

Martin T m4rtntns at gmail.com
Fri Mar 9 07:41:25 EST 2018


Hi,

let's say that I have a SLAX script which takes an argument named
"interface". This "interface" can be an IFD. Is it possible to create
an XPath statement for for-each loop, which runs for each interface if
the "interface" is not specified and only for this one specific IFD,
if "interface" is specified? My first idea was to do something like
this:

param $interface = "*";

for-each ($result/physical-interface[name == $interface) {

}

This works only in case the "interface" argument is specified. When
the "interface" argument is not specified, then interfaces with the
literal name of * are searched and obviously, none are found. When I
define the "interface" parameter like this:

param $interface = *;

..then nothing is printed because $interface seems to be an empty
node-set. As a next step, I tried with conditional statement:

for-each ($result/physical-interface[name == (($interface) ? $interface : *)]) {

}

..or:

for-each ($result/physical-interface[name == (($interface != "") ?
$interface : *)]) {

}

..but those do not work either. On the other hand, "[name == *]" works fine.

Am I doing it wrong or such statements are not supported?


thanks,
Martin


More information about the juniper-nsp mailing list