[j-nsp] understaning the copy-node in SLAX

Martin T m4rtntns at gmail.com
Fri Feb 2 12:25:23 EST 2018


Hi!

Let's say that I have the following node-set type variable and for-each loop:

var $results := {
    <abc a="12" b="34" c="56"> {
        <klm k="78"> {
            <name n="9"> "foo";
            <name n="9"> "bar";
        }
    }
}

for-each ($results/abc) {
    copy-node {
        for-each (@*) {
            attribute name(.) {
                expr .;
            }
        }
    }
}

When I run this with traceoptions enabled, then I can see that "<abc
a="12" b="34" c="56"/>" is present in the output document. I guess
that this inner for-each loop, based on my example, expands to this:

copy-node {
    attribute "a" {
        expr 12;
    }
    attribute "b" {
        expr 34;
    }
    attribute "c" {
        expr 56;
    }
}

Now "copy-node" does its shallow copy and copies "abc" element node
and specified three attribute nodes to result tree. Am I correct? In
addition, why does copy-node run only once despite the fact that it is
in the for-each loop? Is it because copy-node discards all the child
elements of its current node and thus there are no more element
nodes(<klm>, <name>, <name> based on my example) to loop through?


thanks,
Martin


More information about the juniper-nsp mailing list