...So it is always wise to give elite attackers in stack (esp. like swordsmen) "sentr(y)" order instead of fortifying. Or just skip them. With robust number of primary defensive fortified units, of course.
This really only applies when your troops are inside walled towns/ cities, though.
Out in the field, you need to be more careful, because while there is still little difference (or none) between your 'attacker' and 'defender' base D-values, then unless the fortified vUnit gets a significant D-bonus from the terrain (+50% or better, i.e. Hills, Volcanoes, Mountains), the algorithm will almost always pick the eUnit to defend -- even if it is the most valuable in terms of shield-cost/promotions. And you can't fortify
any M=1 units on the turn you cross into enemy territory, when your troops are at their most vulnerable.
If you're still in the initial stages of a war, it may actually be better to keep your eSwords in a front-line/ chokepoint city, to pick off the incoming on your turf: let the AI troops come to you, and kill/injure at least their fast-attackers, where you have the movement advantage (assuming roads -- you did build roads, right?). Once you go on the offensive,
if you can be reasonably sure that you've killed the bulk of the AI's immediately available attackers, then by all means, send your eSwords along with the stack. If the AI is still throwing units at you though, it may be better to hold your eSwords behind your border, let your vUnits do the grunt work on the initial incursion(s), and then move the eSwords into your newly captured territory to help quell the enemy city(s), and be ready to fight off the next wave(s) (if any). (DON'T leave them in the city longer then 1T, though!)
Obviously this no longer applies after you get Feudalism/ Pikes -- a vPike, especially if fortified on a decent defensive tile, will almost always be assigned as top defender over an eSword or eMace. Including bombardment-units doesn't hurt either, if your stack is restricted to 1-tile moves anyway.
TL: DR
The above notwithstanding, there's a very simple way to know which unit will defend a stack (first) -- when no unit in that stack is the currently active unit, the defender will be the one that shows on top.