}
prefixStack.addFirst(prefix);
// If the namespace is already registered, then we'll have to register it in the context's registry, too.
if (!namespaceRegistry.isRegisteredNamespaceUri(uri)) {
ExecutionContext destinationContext = destination.getExecutionContext();
// The namespace is not already registered (locally or in the context's registry), so we have to
// register it with the context's registry (which the local register then inherits).
NamespaceRegistry contextRegistry = destinationContext.getNamespaceRegistry();
if (contextRegistry.getNamespaceForPrefix(prefix) != null) {
// The prefix is already bound, so register and generate a unique prefix
destinationContext.getNamespaceRegistry().getPrefixForNamespaceUri(uri, true);
// Now register locally with the supplied prefix ...
namespaceRegistry.register(prefix, uri);
} else {
destinationContext.getNamespaceRegistry().register(prefix, uri);
}
} else {
// It is already registered, but re-register it locally using the supplied prefix ...
namespaceRegistry.register(prefix, uri);
}