Joseph is chosen among the descendants of David to be betrothed to the Virgin Mary.
Original Source:
The Golden Legend, vol. 5: The Nativity of our Blessed Lady
Anon came a voice out of the oracle and said that, all they that were of the house of David that were convenable to be married and had no wife, that each of them should bring a rod to the altar, and his rod that flourished, and, after the saying of Isaiah, the Holy Ghost sit in the form of a dove on it, he should be the man that should be desponsate and married to the Virgin Mary. And Joseph, of the house of David, was there among the others, and him seemed to be a thing unconvenable, a man of so old age as he was to have so tender a maid, and whereas others brought forth their rods he hid his. And when nothing appeared according to the voice of God, the bishop ordained for to ask counsel again of our Lord. And he answered that, he only that should espouse the virgin had not brought forth his rod. And then Joseph by the commandment of the bishop brought forth his rod, and anon it flowered, and a dove descended from heaven thereupon, so that it was clearly the advice of every man that he should have the virgin. And then he espoused the Virgin Mary, and returned into his city of Bethlehem for to ordain his meiny and his house, and for to fetch such things as were necessary. And the Virgin Mary returned unto the house of her father with seven virgins, her fellows of her age, which had seen the demonstrance of the miracle.
The Golden Legend or Lives of the Saints. Compiled by Jacobus de Voragine, Archbishop of Genoa, 1275. First Edition Published 1470. Englished by William Caxton, First Edition 1483, Edited by F.S. Ellis, Temple Classics, 1900 (Reprinted 1922, 1931.)