11-21-2009 09:26 AM
I'm trying to get the value of a set policer depending on what encapsulation is set on a unit. Since family inet has not encapsulation set, I've used the if clause below to set family to 'inet' if no encapsulation is set. This works well.
var $family = {
if ($top/interfaces/interface[name == $phyifname]/unit[name == $unit]/encapsulation) {
expr $top/interfaces/interface[name == $phyifname]/unit[name == $unit]/encapsulation;
} else {
expr "inet";
}
}
var $policer_in = $top/interfaces/interface[name == $phyifname]/unit[name == $unit]/family[name == $family]/policer/input;
var $policer_out = $top/interfaces/interface[name == $phyifname]/unit[name == $unit]/family[name == $family]/policer/output;The problem comes in the last two lines. The 'family[name == $family]' doesn't work as I'd expect. I believe this is because family xxx is its own node (whats the right term for this?), as opposed to a node that expects an argument (ie, name in slax)
Can someone set me in the right direction on this?
Solved! Go to Solution.
11-21-2009 02:32 PM
You can check the name of the context node by using the name() function.
So something like this might be what you are looking for:
var $policer_in = $top/interfaces/interface[name == $phyifname]/unit[name == $unit]/family/*[name() == $family]/policer/input;
11-21-2009 05:16 PM
That worked nicely. What is the * for before [name()... ?
11-21-2009 05:22 PM
* is the wildcard that matches all nodes for the given axis. The default axis is child, so the * in that location path matches all child nodes of <family> and then the predicate [ ] narrows them down to only child nodes with the same name as the $family variable.