The following can only replace the first value, and not others. Can someone help me understand why the other nodes gets empty value?
On the face of it, the code seems to intend to replace the new_year text by the correspondance, in position, old_year text value. It should run fine except that the last replacement wouldn't take place because the position() is 1-based rather than 0-based.
If you replace this
xpathReplace(doc,"/doc/data/new_year[" + i + "]","/doc/data/old_year[" + i + "]");
by this
the replacement will be complete.
But is that the problem or what you desire to happen?