Getting sleeper tickets out of Xi'an to anywhere has been an obnoxious exercise for many years--as long as I can remember and at nearly all times of the year. Somebody on the ground in Xi'an needs to be working on your behalf to get those, especially if your plans are kind of tight and you can't take pot luck or hang out for extra days. For those who want to do train one way and fly the other, usually easier to train Beijing-Xi'an and then fly back.
Note that now there are alternate ways to train back that require only seat tickets, not those precious sleepers:
1) Leave Xi'an North station in the morning on a G bullet train to Zhengzhou, change to a D train for Beijing arriving late afternoon.
2) Spend most of the day in Xi'an, leave late afternoon from Xi'an North station on the G bullet train to Zhengzhou and then change to a night-time Beijing-bound D train. (For those who don't mind not stretching out to sleep.)
3) Xi'an North G train to Zhengzhou late afternoon, spend the night in a hotel in Zhengzhou, then take the 7:30 D train Zhengzhou to Beijing arriving at lunchtime.