Yes, this is fine, as long as the train stops there.
Trains do not stop at the border, a border means: the tariff of one country stops there and the others starts to work from there. Exeptions are the so-called common-tariff-points. F.i. Salzburg is an Austrian-city, but if you travel from Salzburg Main-station (in german-called Hbf) to Freilassing, of further, than you pay according to the German rate and you are travelling under the conditions of the German Carrier. The mostcommon-tariffpoints are between Germany, Switzerland and Austria and between Austria/Switzerland and Italy.
But you can buy a ticket to the border, for some countries easy, f.i. from The Nederlands to Germany, you can buy with the Option NL 100, than you pay only for the German part. If you have a Bahncard 25, or 50, you can switch on the BahnCard-reduction, then you'll get 25, or 50% reduction for the german part of the trip. You can buy a Sparpreis (or Supersparpreis) for getting the lowest-prices, but they are only applicable with the part from the station in which you'll hop on the train and - off course with train-connection on the german part of the trip (and then it would be the question or using a travel-day will be usefull or not (in the most cases not!).