why resolving the d:file/@href with $base here ? wouldn't it be more correct to delete:

//d:file[not(resolve-uri(@href,base-uri(.))=$resolve-href)]