Nokia N97 and Nokia 5800 XpressMusic were Nokia's first mass produced, mass market "iPhone killers", and they were half-assed responses at best.
Nokia N8 was their first device that was truly competitive with iPhone, and by then, the image of Nokia as a cutting edge smartphone brand was already in decline.
A lot of iPhone's edge, by then, wasn't just in the touch-native UX, but also in app support (developers! developers! developers!), and they had the mindshare advantage there.
Nokia N9 was even better in a vacuum - but was even more late to market, and had even worse app support.