We can simplify the scenario. Let's focus on the relevant details only:
The attacker is already hidden, and they do not do anything else to give their location away prior to attacking you.
You are trying to ready an action to attack them after they appear but before they can attack.
The following description of the Ready action states how you can use it (Player's Handbook p. 193, emphasis mine):
Ready. Sometimes you want to get the jump on a foe or wait for a particular circumstance before you act. To do so, you can take the Ready action on your turn, which lets you act using your reaction before the start of your next turn. First, you decide what perceivable circumstance will trigger your reaction. Then, you choose the action you will take in response to that trigger, or you choose to move up to your speed in response to it.
So you can ready an action to trigger on a perceivable circumstance only, meaning that you have to be able to notice the circumstance in order for the readied action to trigger.
The problem is that you won't be able to perceive the enemy coming out of hiding before they make their attack. The following describes attacks from hidden attackers (Player's Handbook p. 194, emphasis mine):
Unseen Attackers and Targets. If you are hidden--both unseen and unheard--when you make an attack, you give away your location when the attack hits or misses.
So their location will not be given away until the attack hits or misses. By the time you perceive that they have come out of hiding to attack you, they have already hit or miss on their attack. Therefore you cannot interrupt them in the attempt.
That's under assumptions 1 and 2 that I stated at the beginning, which basically distilled the important aspects of the scenario you describe.
But, if the hidden attacker did something else prior to their attack to give their location away, something perceivable, then your readied action could trigger before they get to attack. For example, if they give away their location by opening a door or making a loud sound first, you could do so because you would perceive that occurrence prior to their attempt to attack you.
In addition, note that whether the enemy's attack hit or miss you can still follow-up after that with your readied attack action. So, if the enemy in fact missed, your readied attack can still trigger because you perceived their location as soon as they missed. They do not get to stay hidden for free after a miss unless they have a special feature allowing it.