This is very similar to <xsl:include>
, but import
precedence has to be handled differently. Looking at the code you'll find
this fragment:
| | |
|
// Handle precedence for the including stylesheet
final int currPrecedence = parser.getCurrentImportPrecedence();
final int nextPrecedence = parser.getNextImportPrecedence();
_imported.setImportPrecedence(currPrecedence);
context.setImportPrecedence(nextPrecedence); | |
| | |
The important thing here is that the imported stylesheet has import
precedence less than the importing stylesheet. So the imported
stylesheet gets the current import precedence, while the current stylesheet
gets the next available (unused) import precedence. The
Stylesheet
class has a method
setImportPrecedence()
that ensures that the import precedence
is set not only for the stylesheet itself, but that it is also propagated
down to any included/imported stylesheets:
| | |
|
public void setImportPrecedence(final int precedence) {
// Set import precedence for this stylesheet
_importPrecedence = precedence;
// Set import precedence for all included stylesheets
final Enumeration elements = elements();
while (elements.hasMoreElements()) {
SyntaxTreeNode child = (SyntaxTreeNode)elements.nextElement();
if (child instanceof Include) {
Stylesheet included = ((Include)child).getIncludedStylesheet();
if (included != null) included.setImportPrecedence(precedence);
}
}
// Set import precedence for the stylesheet that imported this one
if (_importedFrom != null) {
if (_importedFrom.getImportPrecedence() < precedence) {
final Parser parser = getParser();
final int nextPrecedence = parser.getNextImportPrecedence();
_importedFrom.setImportPrecedence(nextPrecedence);
}
}
// Set import precedence for the stylesheet that included this one
else if (_includedFrom != null) {
if (_includedFrom.getImportPrecedence() != precedence)
_includedFrom.setImportPrecedence(precedence);
}
} | |
| | |
This method has been carefully cluttered together, and it works, and it
should not be touched.