The way to write this document is the way you approach writing any workplace document where the boundaries are set for you by the professional tone of the relationships established inside the environment:
Who is the reader? To a person who has just experienced a great loss
What is your purpose? The express your understanding and sympathy for this great loss
Occasion? Something serious has happened to a coworker outside of the workplace but the behavior and productivity of the worker will most likely be affected and needed to be understood and taken into consideration until such time as the shock of loss fades and the adjustments begin.
If you do not know the person well and don't want to write a fulsome personal letter on your notecard or a sheaf of fine cream-colored paper, find a sensitive card and send it.
However, if you work closely with the person, follow the guidelines for content after answering the questions you always ask and answer before writing a workplace-affiliated document.
Spell the person's name correctly.
If you have read the obituary, mention the deceased person by name and recognize the relationship.
Do not immediately recount a major story of your own loss and explain how hard that was for you.
This letter is about the reader's loss, not yours.
Offer to help in any way you can.
Sign it sincerely.
Until you have experienced a major personal loss due to death, you won't fully understand how to write this note or choose that card.
Until then, express your condolence and offer your abiding presence as a help in time of trouble.
That's what someone needs, and it is all that is expected of a mature and caring co-worker.