I've been working through the problem to the point where I am confident that in a condition block I am only seeing the nodes I want, but I don't think that removeAllNodes and removeFirstNode is doing what I expect it to do. Instead of deleting the matching segment, it either deletes all DG1 segments or deletes the first DG1 segment (instead of the matching segments).
In this example below, I have 14 DG1 segments, and the last 2 (13 and 14) match the condition.
var nodes = message.getAllNodes('DG1');
for (var i=0; i < nodes.length; i++) {
if (StringUtils.contains(nodes[i], 'I9')) {
//message.removeAllNodes('DG1['+nodes[i]+']'); // This deletes all DG1 segments
message.removeFirstNode('DG1['+nodes[i]+']'); // This deletes the first and second DG1 segments.
}
}