// If the namespace is already registered, then we'll have to register it in the context's registry, too.
if (!namespaceRegistry.isRegisteredNamespaceUri(uri)) {
// 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 = context.getNamespaceRegistry();
if (contextRegistry.getNamespaceForPrefix(prefix) != null) {
// The prefix is already bound, so register and generate a unique prefix
context.getNamespaceRegistry().getPrefixForNamespaceUri(uri, true);
// Now register locally with the supplied prefix ...
namespaceRegistry.register(prefix, uri);
} else {