Technically, if its OEM Win 7 (it came on the desktop preinstalled), no. That's MS rules on OS transfer.
However, I'd be more concerned with other aspects.. If the machine ran Win XP, that places it around 10 years old.. I doubt win 7 would run very well on it. You're most likely limited by dated hardware.