*/
public void apply(XPathContext context) {
switch (position) {
case FIRST: {
NodeList list = content.getChildNodes();
int count = list.getLength();
for (int i=count-1; i>=0; i--) {
targetNode.insertFirst(list.getItem(i));
}
break;
}
case LAST:{
while (content.hasChildNodes()) {
targetNode.appendChild(content.getFirstChild());
}
break;
}
case BEFORE: {
Node refNode = targetNode.getChild(position);
NodeList list = content.getChildNodes();
int count = list.getLength();
for (int i=0; i < count; i++) {
targetNode.insertBefore(list.getItem(i), refNode);
}
break;
}
case AFTER: {
Node refNode = targetNode.getChild(position);
NodeList list = content.getChildNodes();
int count = list.getLength();
for (int i=count-1; i>=0; i--) {
targetNode.insertAfter(list.getItem(i), refNode);
}
break;
}
default:
throw new UnsupportedOperationException("Unknown insert position " + position);