parent.insertBefore(contentSeq.toNodeSet(), node);
parent.insertBefore(contentList, node);
	public Sequence eval(Sequence contextSequence, Item contextItem)			throws XPathException {		if (contextItem != null)			contextSequence = contextItem.toSequence();		Sequence inSeq = select.eval(contextSequence);		if (inSeq.getLength() == 0)			return Sequence.EMPTY_SEQUENCE;		if (!Type.subTypeOf(inSeq.getItemType(), Type.NODE))			throw new XPathException(getASTNode(), Messages.getMessage(Error.UPDATE_SELECT_TYPE));				Sequence contentSeq = value.eval(contextSequence);		if (contentSeq.getLength() == 0)			throw new XPathException(getASTNode(), Messages.getMessage(Error.UPDATE_EMPTY_CONTENT));        try {            NodeImpl[] ql = selectAndLock(inSeq.toNodeSet());            IndexListener listener = new IndexListener(ql);            NodeImpl node;            NodeImpl parent;            DocumentImpl doc = null;            Collection collection = null, prevCollection = null;            DocumentSet modifiedDocs = new DocumentSet();            int len = contentSeq.getLength();            LOG.debug("found " + len + " nodes to insert");            for (int i = 0; i < ql.length; i++) {                node = ql[i];                doc = (DocumentImpl) node.getOwnerDocument();                doc.setIndexListener(listener);                collection = doc.getCollection();                if (prevCollection != null && collection != prevCollection)                        doc.getBroker().saveCollection(prevCollection);                if (!doc.getPermissions().validate(context.getUser(),                        Permission.UPDATE))                        throw new XPathException(getASTNode(),                                "permission to remove document denied");                modifiedDocs.add(doc);				if (mode == INSERT_APPEND) {					node.appendChildren(contentSeq.toNodeSet(), -1);				} else {	                parent = (NodeImpl) node.getParentNode();	                switch (mode) {	                    case INSERT_BEFORE:	                        parent.insertBefore(contentSeq.toNodeSet(), node);	                        break;	                    case INSERT_AFTER:	                        ((NodeImpl) parent).insertAfter(contentSeq.toNodeSet(), node);	                        break;	                }				}                doc.clearIndexListener();                doc.setLastModified(System.currentTimeMillis());                prevCollection = collection;            }            if (doc != null) doc.getBroker().saveCollection(collection);            checkFragmentation(modifiedDocs);        } catch (PermissionDeniedException e) {			// TODO Auto-generated catch block			e.printStackTrace();		} catch (EXistException e) {			// TODO Auto-generated catch block			e.printStackTrace();		} catch (LockException e) {			// TODO Auto-generated catch block			e.printStackTrace();		} catch (XPathException e) {			// TODO Auto-generated catch block			e.printStackTrace();		} finally {            unlockDocuments();        }		return Sequence.EMPTY_SEQUENCE;	}