public DocumentImpl loadStylesheetModule(DocumentInfo rawDoc)
throws XPathException {
StyleNodeFactory nodeFactory = getStyleNodeFactory();
LinkedTreeBuilder styleBuilder = new LinkedTreeBuilder();
PipelineConfiguration pipe = getConfiguration().makePipelineConfiguration();
styleBuilder.setPipelineConfiguration(pipe);
styleBuilder.setSystemId(rawDoc.getSystemId());
styleBuilder.setNodeFactory(nodeFactory);
StartTagBuffer startTagBuffer = new StartTagBuffer();
NamespaceReducer nsReducer = new NamespaceReducer();
nsReducer.setUnderlyingReceiver(startTagBuffer);
UseWhenFilter useWhenFilter = new UseWhenFilter(startTagBuffer, nsReducer);
useWhenFilter.setUnderlyingReceiver(styleBuilder);
startTagBuffer.setUnderlyingReceiver(useWhenFilter);
StylesheetStripper styleStripper = new StylesheetStripper();
styleStripper.setUnderlyingReceiver(nsReducer);
CommentStripper commentStripper = new CommentStripper();
commentStripper.setUnderlyingReceiver(styleStripper);
commentStripper.setPipelineConfiguration(pipe);
// build the stylesheet document
commentStripper.open();
rawDoc.copy(commentStripper, CopyOptions.ALL_NAMESPACES);
commentStripper.close();
DocumentImpl doc = (DocumentImpl)styleBuilder.getCurrentRoot();
styleBuilder.reset();
return doc;
}