CharSequence format = formatExpression.evaluateAsString(context);
String[] parts;
try {
parts = controller.getConfiguration().getNameChecker().getQNameParts(format);
} catch (QNameException e) {
XPathException err = new XPathException("The requested output format " + Err.wrap(format) + " is not a valid QName");
err.setErrorCode("XTDE1460");
err.setXPathContext(context);
throw err;
}
String uri = nsResolver.getURIForPrefix(parts[0], false);
if (uri == null) {
XPathException err = new XPathException("The namespace prefix in the format name " + format + " is undeclared");
err.setErrorCode("XTDE1460");
err.setXPathContext(context);
throw err;
}
StructuredQName qName = new StructuredQName(parts[0], uri, parts[1]);
computedGlobalProps = getExecutable().getOutputProperties(qName);
if (computedGlobalProps == null) {
XPathException err = new XPathException("There is no xsl:output format named " + format);
err.setErrorCode("XTDE1460");
err.setXPathContext(context);
throw err;
}
}
// Now combine the properties specified on xsl:result-document with those specified on xsl:output
Properties computedLocalProps = new Properties(computedGlobalProps);
// First handle the properties with fixed values on xsl:result-document
final NameChecker checker = config.getNameChecker();
for (Iterator citer = localProperties.keySet().iterator(); citer.hasNext();) {
String key = (String)citer.next();
String[] parts = NamePool.parseClarkName(key);
try {
setSerializationProperty(computedLocalProps, parts[0], parts[1],
localProperties.getProperty(key), nsResolver, true, config);
} catch (XPathException e) {
e.maybeSetLocation(this);
throw e;
}
}
// Now add the properties that were specified as AVTs
if (serializationAttributes.size() > 0) {
for (IntIterator it = serializationAttributes.keyIterator(); it.hasNext();) {
int key = it.next();
Expression exp = serializationAttributes.get(key);
String value = exp.evaluateAsString(context).toString();
String lname = namePool.getLocalName(key);
String uri = namePool.getURI(key);
try {
setSerializationProperty(computedLocalProps, uri, lname, value, nsResolver, false, config);
} catch (XPathException e) {
e.maybeSetLocation(this);
e.maybeSetContext(context);
if (NamespaceConstant.SAXON.equals(e.getErrorCodeNamespace()) &&
"SXWN".equals(e.getErrorCodeLocalPart().substring(0, 4))) {
try {
context.getController().getErrorListener().warning(e);
} catch (TransformerException e2) {
throw XPathException.makeXPathException(e2);
}
} else {
throw e;
}
}
}
}
// Handle properties specified using a dynamic xsl:output element
// (Used when the instruction is generated from a saxon:result-document extension function call)
if (dynamicOutputElement != null) {
Item outputArg = dynamicOutputElement.evaluateItem(context);
if (!(outputArg instanceof NodeInfo &&
((NodeInfo)outputArg).getNodeKind() == Type.ELEMENT &&
((NodeInfo)outputArg).getFingerprint() == StandardNames.XSL_OUTPUT)) {
XPathException err = new XPathException(
"The third argument of saxon:result-document must be an <xsl:output> element");
err.setLocator(this);
err.setXPathContext(context);
throw err;
}
Properties dynamicProperties = new Properties();
processXslOutputElement((NodeInfo)outputArg, dynamicProperties, context);
for (Iterator it = dynamicProperties.keySet().iterator(); it.hasNext();) {