New tree manipulation functions: transform and duplicate.