Yes, but the discounting will be exactly offset by the higher yield of the “new” 5-year compared with the “old” 10-year.
You are forgetting transaction costs. There is no point in the sale/purchase at the 5 year point if it ends up being a wash. All you are doing is feeding the broker. Second part of the problem is that if the interest rates are rising as the sale/purchase is being done, the discount will be affected by anticipations of further rate increases.