To reiterate the answers above, no, of course he couldn't have used attempting to rape one person as a defence to raping another! He used belief in consensual sex with one person as a defence to raping another. Completely and totally different.
You may think, based on what you have read, that this is rubbish, that the jury should have seen through it, that they should have dismissed his account and preferred hers. That is a separate matter - the account he apparently gave is CAPABLE of amounting to a defence in law. That doesn't mean that it is a sure get-off mechanism, just that he is saying something that would not immediately make the judge say "hang on a second, this man is admitting to an offence".
We don't know what happened in the courtroom - we only know what the journalists in the courtroom wanted us to know/think/believe. That may or may not be accurate. He may have come across very plausibly and she may have given poor evidence. She may have been cross-examined about demonstrable lies. She may have given contradictory evidence. She may have given an account that was inconsistent with the forensic evidence. She may have a history of making false allegations - that might be something that was aduced in evidence but that the press were not permitted to report on. Alternatively she might have given credible, harrowing, compelling evidence, but 3 members of the jury might just not quite have been able to get past that element of doubt.
The low rate of rape cases that come to court is a real concern and things need to change in the way we,as a society, view rape victims. What doesn't need to change is the law. It worries me that there is always an outcry in the aftermath of these cases that the law should be changed, that juries should be scrapped in rape cases, that defence lawyers shouldn't represent defendants etc etc. That is a very scary road to even think about going down - there are countries where these rights do not exist and I doubt any of us would want to live there.
I represented a young man once, in his early twenties, good character, respected in his local area, hard-working etc. He was accused of a truly horrendous series of sexual assaults, rape and buggery on a young woman. His casetook over a year to come to trial and in the interim he was beaten up, lost his job, had members of his family turn against him, had messages scrawled on his partner's home, things pushed through his letter-box, the works. During the trial it came out (beyond any doubt whatsoever) that the allegations were fabricated after he rejected her. The officer shook his hand and apologised to him. The jury cried. He sat in the corridor afterwards crying like a baby and saying that this had ruined his life and he would never be allowed to move past it, that mud sticks. I made soothing noises and said no, no, people will see that you are innocent.
Clearly I was talking out of my arse.