toplevel = (getParentNode() instanceof XSLStylesheet);
resultNameCode = getNameCode();
NamePool namePool = getNamePool();
short elementURICode = namePool.getURICode(resultNameCode);
if (toplevel) {
// A top-level element can never be a "real" literal result element,
// but this class gets used for unknown elements found at the top level
if (elementURICode == 0) {
compileError("Top level elements must have a non-null namespace URI");
}
} else {
// Build the list of output namespace nodes
// Up to 5.3.1 we listed the namespace nodes associated with this element that were not also
// associated with an ancestor literal result element (because those will already
// have been output). Unfortunately this isn't true if the namespace was present on an outer
// LRE, and was excluded at that level using exclude-result-prefixes, and is now used in an
// inner element: bug 5.3.1/006
// We now use a different optimisation: if
// (a) this LRE has a parent that is also an LRE, and
// (b) this LRE has no namespace declarations of its own, and
// (c) this element name is in the same namespace as its parent, and
// (d) the parent doesn't specify xsl:inherit-namespaces="no"
// (e) there are no attributes in a non-null namespace,
// then we don't need to output any namespace declarations to the result.
boolean optimizeNS = false;
NodeInfo parent = getParent();
if ((parent instanceof LiteralResultElement) &&
((LiteralResultElement)parent).inheritNamespaces &&
(namespaceList==null || namespaceList.length==0) &&
( elementURICode == namePool.getURICode(getParent().getFingerprint()))) {
optimizeNS = true;
}
if (optimizeNS) {
for (int a=0; a<attributeList.getLength(); a++ ) {
if (((attributeList.getNameCode(a)>>20)&0xff) != 0) { // prefix != ""
optimizeNS = false;
break;
}
}
}
if (optimizeNS) {
namespaceCodes = new int[0];
} else {
namespaceCodes = getNamespaceCodes();
}
// apply any aliases required to create the list of output namespaces
XSLStylesheet sheet = getPrincipalStylesheet();
if (sheet.hasNamespaceAliases()) {
for (int i=0; i<namespaceCodes.length; i++) {
// System.err.println("Examining namespace " + namespaceCodes[i]);
short scode = (short)(namespaceCodes[i]&0xffff);
int ncode = sheet.getNamespaceAlias(scode);
if (ncode != -1 && (ncode & 0xffff) != scode) {
// apply the namespace alias. Change in 7.3: use the prefix associated
// with the new namespace, not the old prefix.
namespaceCodes[i] = ncode;
}
}
// determine if there is an alias for the namespace of the element name
int ercode = sheet.getNamespaceAlias(elementURICode);
if ((ercode & 0xffff) != elementURICode) {
elementURICode = (short)(ercode & 0xffff);
resultNameCode = namePool.allocate(namePool.getPrefixFromNamespaceCode(ercode),
namePool.getURIFromNamespaceCode(ercode),
getLocalPart());
}
}
// deal with special attributes
String useAttSets = getAttributeValue(StandardNames.XSL_USE_ATTRIBUTE_SETS);
if (useAttSets != null) {
attributeSets = getAttributeSets(useAttSets, null);
}
String type = getAttributeValue(StandardNames.XSL_TYPE);
if (type != null) {
if (!getConfiguration().isSchemaAware(Configuration.XSLT)) {
compileError("The xsl:type attribute is available only with a schema-aware XSLT processor");
}
schemaType = getSchemaType(type);
}
String validate = getAttributeValue(StandardNames.XSL_VALIDATION);
if (validate != null) {
validation = Validation.getCode(validate);
if (validation != Validation.STRIP && !getConfiguration().isSchemaAware(Configuration.XSLT)) {
compileError("To perform validation, a schema-aware XSLT processor is needed");
}
if (validation == Validation.INVALID) {
compileError("Invalid value for xsl:validation. " +
"Permitted values are (strict, lax, preserve, strip)");
}
} else {
validation = getContainingStylesheet().getDefaultValidation();
}
// establish the names to be used for all the output attributes;
// also type-check the AVT expressions
short attributeURIs[] = new short[numberOfAttributes];
if (numberOfAttributes > 0) {
for (int i=0; i<numberOfAttributes; i++) {
int anameCode = attributeNames[i];
int alias = anameCode;
short attURIcode = namePool.getURICode(anameCode);
if (attURIcode!=0) { // attribute has a namespace prefix
int newNSCode = sheet.getNamespaceAlias(attURIcode);
if ((newNSCode & 0xffff) != attURIcode) {
attURIcode = (short)(newNSCode & 0xffff);
alias = namePool.allocate( namePool.getPrefixFromNamespaceCode(newNSCode),
namePool.getURIFromNamespaceCode(newNSCode),
attributeList.getLocalName(i));
}
}
//attributeNames[i] = translate(alias);
attributeNames[i] = alias;
attributeURIs[i] = attURIcode;
attributeValues[i] = typeCheck(namePool.getDisplayName(alias), attributeValues[i]);
}
}
// remove any namespaces that are on the exclude-result-prefixes list, unless it is
// the namespace of the element or an attribute