Replace entries in a single branch only of an existing tree with several branches based on an if condition