String uri = null;
// name needs to be evaluated at run-time
AtomicValue nameValue = (AtomicValue)elementName.evaluateItem(context);
if (nameValue == null) {
XPathException err1 = new XPathException("Invalid element name (empty sequence)", this);
err1.setErrorCode((isXSLT() ? "XTDE0820" : "XPTY0004"));
err1.setXPathContext(context);
throw dynamicError(this, err1, context);
}
//nameValue = nameValue.getPrimitiveValue();
if (nameValue instanceof StringValue) { // which includes UntypedAtomic
// this will always be the case in XSLT
CharSequence rawName = nameValue.getStringValueCS();
try {
String[] parts = controller.getConfiguration().getNameChecker().getQNameParts(rawName);
prefix = parts[0];
localName = parts[1];
} catch (QNameException err) {
XPathException err1 = new XPathException("Invalid element name. " + err.getMessage(), this);
err1.setErrorCode((isXSLT() ? "XTDE0820" : "XQDY0074"));
err1.setXPathContext(context);
throw dynamicError(this, err1, context);
}
} else if (nameValue instanceof QNameValue && allowNameAsQName) {
// this is allowed in XQuery
localName = ((QNameValue)nameValue).getLocalName();
uri = ((QNameValue)nameValue).getNamespaceURI();
if (uri == null) {
uri = "";
}
prefix = ((QNameValue)nameValue).getPrefix();
} else {
XPathException err = new XPathException("Computed element name has incorrect type");
err.setErrorCode((isXSLT() ? "XTDE0820" : "XPTY0004"));
err.setIsTypeError(true);
err.setXPathContext(context);
throw dynamicError(this, err, context);
}
if (namespace == null && uri == null) {
// if (prefix.length() == 0) {
// uri = defaultNamespace;
// } else {
uri = nsContext.getURIForPrefix(prefix, true);
if (uri == null) {
XPathException err = new XPathException("Undeclared prefix in element name: " + prefix, this);
err.setErrorCode((isXSLT() ? "XTDE0830" : "XQDY0074"));
err.setXPathContext(context);
throw dynamicError(this, err, context);
}
// }
} else {
if (uri == null) {
if (namespace instanceof StringLiteral) {
uri = ((StringLiteral)namespace).getStringValue();
} else {
uri = namespace.evaluateAsString(context).toString();
if (!AnyURIValue.isValidURI(uri)) {
XPathException de = new XPathException("The value of the namespace attribute must be a valid URI");
de.setErrorCode("XTDE0835");
de.setXPathContext(context);
de.setLocator(this);
throw de;
}
}
}
if (uri.length() == 0) {