Two British soldiers were machine-gunned to death in Northern Ireland today in a continuing escalation of violence by Irish nationalist terrorists that coincides with a decision by Prime Minister Margaret Thatcher's government to establish an elected assembly in the British-ruled province.

The soldiers were killed in Londonderry this morning when their unmarked van was riddled with bullets fired by gunmen who had hidden overnight in a nearby house. The Provisional Irish Republican Army claimed responsibility. The attack follows a similar ambush a week ago when three British soldiers were killed by paramilitary Provisional Irish Republican Army gunmen in Belfast.

At about the same time in London, Thatcher's Cabinet approved a proposal by her Northern Ireland secretary, James Prior, to establish the 78-seat assembly in Ulster before the end of this year. It eventually would be given home rule authority over economic and social affairs in the province if its expected Protestant British loyalist majority and Catholic Irish nationalist minority agree on how to share power.

Details of Prior's plan will be presented publicly to the British Parliament Monday in a government white paper. Prior is seeking parliamentary approval of enabling legislation by this summer so an election could be held in Northern Ireland by November, according to British officials.

The plan is intended as a compromise of demands by Ulster Protestant loyalists for unfettered majority home rule and by Catholic Irish nationalists for movement away from British rule toward a unification with the neighboring Republic of Ireland. Political leaders on both sides in Northern Ireland have expressed displeasure with Prior's general outline of the plan in recent private meetings, but none have yet said they would boycott the proposed election.

From their opposite perspectives, both sides are expected to judge the plan by how far it goes in trying to ensure the Catholic minority a share in local home rule in Northern Ireland and to establish links with Ireland, such as through a consultative body of British, Irish and Northern Ireland legislators.

Ireland's new prime minister, Charles Haughey, and his foreign minister, Gerald Collins, already have criticized Prior's plan as "unworkable." Haughey's government is seeking instead to use recently developed channels of intergovernmental cooperation between Britain and Ireland as a forum for Dublin-London negotiation of an eventual British withdrawal from Northern Ireland and the province's unification in some form with Ireland.

After discussing the plan with Prior here yesterday, Collins told reporters, "I said it was already a failure and would not get off the ground. A failed initiative is probably worse than no initiative at all."

In a speech in Belfast later yesterday, Prior said, "I am not prepared to talk of failure because this is so important for the future of the United Kingdom as well as the people of Northern Ireland that we cannot afford to let it fail. We have all got to work to make it a success."

Without compromise by all sides, he said, there would be no solution to Northern Ireland's sectarian strife and economic depression. "The only winners in a state of continued deadlock would be the men of violence," he said in a Lenten address in St. Anne's Cathedral in Belfast. "The inevitable consequences will be rising unemployment, further hopelessness, frustration and alienation."

Northern Ireland has been ruled directly from London since 1972, when Britain abolished Ulster's Protestant-dominated parliament in an attempt to end discrimination against the Catholic minority and reduce sectarian violence. A power-sharing provincial government set up the next year, with closer links to Ireland and greater initial guarantees of Catholic participation than are expected in Prior's plan, collapsed after a few months in the face of hard-line Protestant opposition and IRA terrorism.

Today's attack occurred just outside St. Eugene's Cathedral in Londonderry. Catholic Bishop Edward Daly heard "a very loud and sustained burst of gunfire" and rushed outside, where a priest, the Rev. Edward Kilpatrick, was the first to reach the fatally wounded soldiers.

The soldiers, Sgt. Michael Burbridge, from Oxfordshire in England, and Cpl. Michael Ward, from London, had just left a nearby fortified police station on the edge of the Catholic Irish nationalist Creggan housing project. Wearing civilian clothes, they were returning to their Army base three miles away.

They had been watched by the gunmen, who had commandeered a nearby house shortly after 9 p.m. yesterday. Seven residents held hostage were left unharmed when the gunmen raced outside this morning, fired two machine guns at the passing van and escaped.

Besides the three soldiers killed last week, an Ulster police inspector was shot to death Sunday by two Provisional IRA gunmen on a motorbike as he left church in Londonderry.

Ulster police officials had claimed that they had crippled the Provisional IRA in recent months when, aided by numerous informers, they arrested and charged more than 200 suspected terrorists.