checkEmpty();
checkTopLevel((this instanceof XSLInclude ? "XTSE0170" : "XTSE0190"));
try {
XSLStylesheet thisSheet = (XSLStylesheet)getParent();
PreparedStylesheet pss = getPreparedStylesheet();
URIResolver resolver = pss.getCompilerInfo().getURIResolver();
Configuration config = pss.getConfiguration();
//System.err.println("GeneralIncorporate: href=" + href + " base=" + getBaseURI());
String relative = href;
String fragment = null;
int hash = relative.indexOf('#');
if (hash == 0 || relative.length() == 0) {
compileError("A stylesheet cannot " + getLocalPart() + " itself",
(this instanceof XSLInclude ? "XTSE0180" : "XTSE0210"));
return null;
} else if (hash == relative.length() - 1) {
relative = relative.substring(0, hash);
} else if (hash > 0) {
if (hash+1 < relative.length()) {
fragment = relative.substring(hash+1);
}
relative = relative.substring(0, hash);
}
Source source;
try {
source = resolver.resolve(relative, getBaseURI());
} catch (TransformerException e) {
throw XPathException.makeXPathException(e);
}
// if a user URI resolver returns null, try the standard one
// (Note, the standard URI resolver never returns null)
if (source==null) {
source = config.getSystemURIResolver().resolve(relative, getBaseURI());
}
if (fragment != null) {
IDFilter filter = new IDFilter(fragment);
source = AugmentedSource.makeAugmentedSource(source);
((AugmentedSource)source).addFilter(filter);
}
// check for recursion
XSLStylesheet anc = thisSheet;
if (source.getSystemId() != null) {
while(anc!=null) {
if (source.getSystemId().equals(anc.getSystemId())) {
compileError("A stylesheet cannot " + getLocalPart() + " itself",
(this instanceof XSLInclude ? "XTSE0180" : "XTSE0210"));
return null;
}
anc = anc.getImporter();
}
}
StyleNodeFactory snFactory = config.getStyleNodeFactory();
includedDoc = pss.loadStylesheetModule(source, snFactory);
// allow the included document to use "Literal Result Element as Stylesheet" syntax
ElementImpl outermost = includedDoc.getDocumentElement();