[j-nsp] set:difference() function in SLAX returns different results while input node-sets are the same
Phil Shafer
phil at juniper.net
Fri Sep 7 13:46:08 EDT 2018
Martin T writes:
>I encountered an interesting behavior where set:difference() function
>does not work when node-set variable is manually defined like this:
Two issues: first is that it is really comparing nodes not contents,
looking to see if the exact references are equal, so comparing:
var $x := {
<a> "a";
<b> {
<a> "a";
}
}
so a and b/a are distinct nodes and comparing them will compare
the specific nodes, not caring that they both contain "a".
Second, the ":=" operators make result tree fragments (RTF) which
are the bane of XSLT. They are not node sets, but behave similarly,
sort of. For details see:
http://juniper.github.io/libslax/slax-manual.html#result-tree-fragments
The outcome is that you'll often need "$var/*" to get to the contents
of the node-set.
See the attached example, where $v3 works and $v2 doesn't.
Thanks,
Phil
% cat /tmp/foo.slax
version 1.2;
var $v1 := {
<vlan> {
<id> "99";
}
<vlan> {
<id> "100";
}
<vlan> {
<id> "101";
}
<vlan> {
<id> "102";
}
}
var $v2 := {
<vlan> {
<id> "99";
}
}
var $v3 = $v1/*[1];
main <top> {
<diff2> {
copy-of set:difference($v1/*, $v2/*);
}
<diff3> {
copy-of set:difference($v1/*, $v3);
}
}
% slaxproc -g -E -d /tmp/foo.slax
sdb: The SLAX Debugger (version 0.22.0)
Type 'help' for help
(sdb) c
<?xml version="1.0"?>
<top>
<diff2>
<vlan>
<id>99</id>
</vlan>
<vlan>
<id>100</id>
</vlan>
<vlan>
<id>101</id>
</vlan>
<vlan>
<id>102</id>
</vlan>
</diff2>
<diff3>
<vlan>
<id>100</id>
</vlan>
<vlan>
<id>101</id>
</vlan>
<vlan>
<id>102</id>
</vlan>
</diff3>
</top>
Script exited normally.
More information about the juniper-nsp
mailing list