Xslt: truncating strings sensibly

Hello!

Is there a rational way in XSLT 1.0 of truncating strings so that the truncate doesn’t occur in the middle of a word?

My idea was to

  1. check if a string is longer than desired, and if yes
  2. truncate it with substring() to an acceptable length plus some leeway
  3. from that, get the substring-before the last ’ ’ (empty space).

But at 3. I am at loss for XSLT-words that will achieve the task.

Thus, the (beginner’s) question: are there any, and if yes, how?

Thanks!!