So, wait, Kingdom Hearts is about sealing up all the worlds' hearts, right? So Ansem wants the hearts so he can be darkness, so Kairi stayed human while Sora lost three hearts at once?
This game is complicated.
Master Xehanort tries to access Kingdom Hearts a source of power
He fails and is split into two, Ansem which is his heartless and Xemnas his nobody.
Both were defeated by Sora. When a person loses their heart they turn into a heartless. If that person was strong of will they will create a nobody as well.
Kingdom Hearts is about stopping Master Xehanort.
She's a princess of heart, her heart was used to open the door along with the other six princesses. Sora restored all their hearts. They are so pure a heartless could form from them. It only leaves them in a catatonic state until it was restored by Sora.