Yup, you need a barracks in the same city as the warriors to upgrade.
Although not directly applicable to your situation (warriors - swordsmen), I thought I'd also let people know that I encountered an upgrade problem that really caught me off guard. I happened to fall
way behind the various AI civs and found myself with neither saltpeter nor the military strength to go take some saltpeter. No problem, I thought, I'll play very, very nice until Nationalism, and upgrade to riflemen then (skipping over musketmen, which require saltpeter; riflemen do not). Built a
bunch of pikemen in the meantime, both as a deterrant and as an "upgrade force" for when I hit Nationalism. Discovered Nationalism; went to upgrade; could not upgrade one single pikeman! until, of course, I sold my first-born for a supply of saltpeter -- then I could upgrade straight to riflemen. Tells me that the upgrade algorithm clearly looks at steps: i.e., spearman to infantry is actually spearman to pikeman, pikeman to musketman, musketman to rifleman, rifleman to infantry; which means you effectively need iron, saltpeter,
and rubber to upgrade that lowly spearman!
Catt