The heresy called Donatism said that the validity of a consecration is dependent upon the priest's holiness. This is not the Catholic view. Even excommunicated and schismatic priests (assuming they were validly ordained priests in the first place) can validly consecrate (perform transubstantiation).
St. Thomas Aquinas answers the question "Whether heretics, schismatics, and excommunicated persons can consecrate?" (Summa Theologica III q. 82 a. 7 c.), saying:
Some have contended that heretics, schismatics, and the excommunicate, who are outside the pale of the Church, cannot perform this sacrament. But herein they are deceived, because, as Augustine says (Contra Parmen. ii), "it is one thing to lack something utterly, and another to have it improperly"; and in like fashion, "it is one thing not to bestow, and quite another to bestow, but not rightly." Accordingly, such as, being within the Church, received the power of consecrating the Eucharist through being ordained to the priesthood, have such power rightly indeed; but they use it improperly if afterwards they be separated from the Church by heresy, schism, or excommunication. But such as are ordained while separated from the Church, have neither the power rightly, nor do they use it rightly. But that in both cases they have the power, is clear from what Augustine says (Contra Parmen. ii), that when they return to the unity of the Church, they are not re-ordained, but are received in their orders. And since the consecration of the Eucharist is an act which follows the power of order, such persons as are separated from the Church by heresy, schism, or excommunication, can indeed consecrate the Eucharist, which on being consecrated by them contains Christ's true body and blood; but they act wrongly, and sin by doing so; and in consequence they do not receive the fruit of the sacrifice, which is a spiritual sacrifice.
In summary: Validly ordained heretical, schismatic, or excommunicated priests can validly consecrate, but they commit an act of profanation in so doing.