Properties changes = nsp.getNamespaces();
NamespaceRegistry nsReg = getRepositorySession().getWorkspace().getNamespaceRegistry();
String[] registeredPrefixes = nsReg.getPrefixes();
for (int i = 0; i < registeredPrefixes.length; i++) {
String prfx = registeredPrefixes[i];
if (!changes.containsKey(prfx)) {
// prefix not present amongst the new values any more > unregister
nsReg.unregisterNamespace(prfx);
} else if (changes.get(prfx).equals(nsReg.getURI(prfx))) {
// present with same uri-value >> no action required
changes.remove(prfx);