The doctrine of extra Ecclesiam nulla salus (outside of the Church there is no salvation) is not to be literally seen as "one must be a baptized Catholic in visible communion with the Church in order to be saved".
The Catechism of the Catholic Church, Second Edition (1997) says of this matter:
1257 The Lord himself affirms that Baptism is necessary for salvation.59 He also commands his disciples to proclaim the Gospel to all nations and to baptize them.60 Baptism is necessary for salvation for those to whom the Gospel has been proclaimed and who have had the possibility of asking for this sacrament.61 The Church does not know of any means other than Baptism that assures entry into eternal beatitude; this is why she takes care not to neglect the mission she has received from the Lord to see that all who can be baptized are "reborn of water and the Spirit." God has bound salvation to the sacrament of Baptism, but he himself is not bound by his sacraments.
1258 The Church has always held the firm conviction that those who suffer death for the sake of the faith without having received Baptism are baptized by their death for and with Christ. This Baptism of blood, like the desire for Baptism, brings about the fruits of Baptism without being a sacrament.
1259 For catechumens who die before their Baptism, their explicit desire to receive it, together with repentance for their sins, and charity, assures them the salvation that they were not able to receive through the sacrament.
1260 "Since Christ died for all, and since all men are in fact called to one and the same destiny, which is divine, we must hold that the Holy Spirit offers to all the possibility of being made partakers, in a way known to God, of the Paschal mystery."62 Every man who is ignorant of the Gospel of Christ and of his Church, but seeks the truth and does the will of God in accordance with his understanding of it, can be saved. It may be supposed that such persons would have desired Baptism explicitly if they had known its necessity.
1261 As regards children who have died without Baptism, the Church can only entrust them to the mercy of God, as she does in her funeral rites for them. Indeed, the great mercy of God who desires that all men should be saved, and Jesus' tenderness toward children which caused him to say: "Let the children come to me, do not hinder them,"63 allow us to hope that there is a way of salvation for children who have died without Baptism. All the more urgent is the Church's call not to prevent little children coming to Christ through the gift of holy Baptism.
59 Cf. ⇒ Jn 3:5[ETML:C/].60 Cf. ⇒ Mt 28:19-20; cf. Council of Trent (1547) DS 1618; LG 14; AG 5.61 Cf. ⇒ Mk 16:16.62 GS 22 # 5; cf. LG 16; AG 7.63⇒ Mk 10 14; cf. ⇒ 1 Tim 2:4.
Baptism by Water is the ordinary means of the Sacrament; however, Baptism by Blood or by Desire are both extraordinary and valid means of the Sacrament. Baptism by Blood is martyrdom; Baptism by Desire is for those who cannot be baptized through no fault of their own because of invincible ignorance (that is, an inability to accept the Church, either by ignorance of Her existence or by unconquerable prejudice). Both these kinds of Baptism are only effected at death.
If someone were to die outside of the Catholic Church by their own fault, however, due to their refusal to accept Her as the One, Holy, Catholic, and Apostolic Church founded by Christ, he would not be saved.
Those who are saved outside of the Catholic Church, whether pagan, Jew, schismatic, or heretic, are not saved because of the untruths of their religion but in spite of them. All who are saved, are saved through the Holy Catholic Church; thus, all who are in the blessed joy of Heaven (the Church Triumphant) are Catholic and thus truly and fully united with Christ.
Note also that the partial truths which other religions hold to varying degrees can indeed be profitable unto salvation, but the fullness of truth is necessary. Thus, extra Ecclesiam nulla salus.