public SelectNode apply(SelectNode sn) { // do a deep copy of the existing query SelectNode before // modifying it: SelectNode newSelectNode = sn.deepCopy(); for (AxisNode an : newSelectNode.getAxisList()) { if (an.getAxis() == axis) { // this is the axis we're drilling ParseTreeNode initialAxisExp = an.getExpression(); // apply the drill operation ParseTreeNode newAxisExp = processAxisExp(initialAxisExp); // replace the expression in the axis by the new generated one an.setExpression(newAxisExp); } } return newSelectNode; }