Champions Novak Djokovic and Roger Federer came through difficult matches to progress to the Wimbledon semifinals.