A series of talks were held by the UK and Spain between 1997 and 2002 on establishing temporary joint sovereignty over Gibraltar .