The Toronto stock market closed higher on the last day of April trading Monday despite data showing an unexpectedly slow Canadian economy and confirmation that Spain is back in recession.

A late-day rally in energy stocks helped push the S&P/TSX composite index up 54.95 points to 12,292.69. while the TSX Venture Exchange rose 11.28 points to 1,424.04.

Statistics Canada reported that gross domestic product declined 0.2% during February. Economists had expected a 0.2% rise during the month. The Canadian dollar was down 0.72 of a cent to 101.22 cents US as traders felt that signs of a weaker economy would delay any move by the Bank of Canada to raise interest rates.

U.S. markets were negative as the Dow Jones industrial average fell 14.68 points to 13,213.63.

The Nasdaq composite index shed 22.84 points to 3,046.36 and the S&P 500 index was off 5.45 points to 1,397.91.

Deteriorating conditions in Europe attracted investor attention Monday as official data confirmed Spain is back in its second recession in three years as its economy shrank by 0.3% in the first quarter following a similar decline in the previous three-month period.

The contraction in Spain is dimming hopes that the government will be able to cut its budget deficit as predicted, which could in turn spell higher borrowing rates as investors lose confidence.

The news wasn’t a huge surprise to markets since it was thought that “the sovereign debt crisis would require such austerity measures that would basically cut into economic growth and that in and of itself would be enough to push the eurozone economy into recession,” said Craig Fehr, Canadian markets strategist at Edward Jones in St. Louis.

“It’s a downward spiral that comes from having to remove the government portion of GDP too early in a recovery.”

Also, ratings agency Standard & Poor’s on Friday downgraded Spain to just three notches above junk. And on Monday, the agency lowered its rating for 11 Spanish banks.

Investors are worried that Spain will not be able to support its banks, which are burdened with massive amounts of bad loans on an imploded property market.

The energy sector led advancers, up 1.46% as oil prices recovered from early lows. The June contract on the New York Mercantile Exchange was off six cents to US$104.87 a barrel. Cenovus Energy (TSX:CVE) declined 68 cents to $35.85 while Canadian Natural Resources (TSX:CNQ) was ahead $1.01 to $34.32.

Tech stocks also advanced with Research In Motion Ltd. (TSX:RIM) ahead 34 cents to $14.13 while MacDonald Dettwiler (TSX:MDA) rose $1.18 to $44.86 ahead of its quarterly earnings report Tuesday.

Metal prices improved with the May copper contract on the Nymex unchanged at US$3.83 a pound. But signs of further economic deterioration sent the base metals sector down 1.39%. First Quantum Minerals (TSX:FM) dropped 61 cents to $20.52 while Ivanhoe Mines (TSX:IVN) gave back 36 cents to $11.53.

The gold sector was also weak, down about 0.3% as June gold declined 60 cents to US$1,664.20 an ounce.

Goldcorp Inc. (TSX:G) has suspended construction of the El Morro gold-copper mine in Chile after the country’s Supreme Court suspended the $3.9-billion project’s environmental permit on Friday. The Supreme Court found Chile’s environmental permitting authority must correct deficiencies identified by the Antofogasta Court of Appeals. Goldcorp shares lost 55 cents to $37.83.

The TSX ended April trading down 99 points from the beginning of the month, leaving the main index up a slight 3.65% year to date. That is in sharp contrast to the S&P 500, which has jumped more than 11% so far in 2012.

But the Toronto market is heavily weighted on the resource side. The energy and materials sectors have suffered from softening economic conditions in emerging countries, particularly China, where the government has tried to engineer a soft landing for the economy in order to ease inflation pressures.

“We think that will continue to weigh on domestic markets in the very near term,” added Fehr.

“But our view is that ultimately a lot of these high growth emerging markets will feed off of the improving growth out of the U.S. and other markets and when that happens, we can expect the Canadian market to participate to the upside.”

Elsewhere on the corporate front, a former executive of Canadian engineering giant SNC-Lavalin (TSX:SNC) has been arrested in Switzerland. Riadh Ben Aissa is accused of fraud and corruption. He was the executive vice-president of construction, but parted ways with the company earlier this year along other SNC executives. Swiss government spokeswoman Jacqueline Buhlman said the allegations are in connection with alleged business dealings in northern Africa, but wouldn’t comment further. SNC shares were up 17 cents to $37.14.

In U.S. corporate news, Barnes & Noble Inc. and Microsoft Corp. are teaming up to create a new Barnes & Noble subsidiary that will house the digital and college businesses of the bookseller and include a Nook application for Windows 8. The companies said Monday that they are exploring separating those businesses entirely. That could mean a stock offering, sale, or other deal could happen and Barnes & Noble shares soared 51.7% to US$20.75.