Dear all,
Once again I need your help

I'm trying to replace a node N with a node N1, only if N is deep-equal() to a node stored into a variable V. The tricky part is that if such a node N does not exist, I have to add the node V to the original set of nodes, i.e.
Code:
<list>
<node1>
<node2>
<node3>
</list>
has to become
Code:
<list>
<v>
<node2>
<node3>
</list>
if "deep-equal($node1, $v) = true()"
or
Code:
<list>
<node1>
<v>
<node3>
</list>
if "deep-equal($node2, $v) = true()"
or
Code:
<list>
<node1>
<node2>
<v>
</list>
if "deep-equal($node3, $v) = true()"
or, finally,
Code:
<list>
<node1>
<node2>
<node3>
<v>
</list>
if no node in ($node1, $node2, $node3) is deep-equal to $v
[suppose that $node{1,2,3} are variables storing the nodes with the same name() of the variable, and that <node{1,2,3}> are nodes with children]
I tried different approaches...using index-of was the one more promising because I could use a variable to store the sequence of nodes under <list> and then check index-of($list-of-nodes, $v)...sadly this function does not use deep-equal to check the equality of $v and the items in $list-of-nodes, thus it doesn't work for my case, where I might have two nodes with same name() but different attributes or other differences in their children that I must consider
Do you have any suggestion?
Thanks in advance for your help!!!