if (processingRootNodes == null || processingRootNodes.size() == 0) {
// If the result is null, there will be no processing to do
document = null;
} else {
final Node firstProcessingRootNode = processingRootNodes.get(0);
if (processingRootNodes.size() == 1 &&
firstProcessingRootNode != null &&
firstProcessingRootNode instanceof Document) {
// If it is a document, just process it as it is output from the filter
document = (Document) firstProcessingRootNode;
} else {
// Fragment exists and it is not a Document. We will therefore lose DOCTYPE
final String documentName = document.getDocumentName();
document = new Document(documentName);
for (final Node processingRootNode : processingRootNodes) {
if (processingRootNode != null) {
final Node clonedProcessingRootNode =
processingRootNode.cloneNode(document, false);
document.addChild(clonedProcessingRootNode);
}
}
document.precompute(this.configuration);