* TSX ends up 43.15 pts, or 0.4 pct, at 11,609.30 * Energy, financial issues lead gains * Gold miners pare gains on Spanish bank worries * China stimulus hopes boost commodities By Jon Cook TORONTO, May 29 (Reuters) - Canadian stocks finished slightly higher on Tuesday, erasing most earlier gains as gold mining firms slid with bullion prices after a downgrade to Spain's sovereign credit rating rekindled fears about Europe's deepening debt crisis. Bullion rose in early trade and then fell as the euro tumbled to its lowest level in nearly two years after credit agency Egan-Jones downgraded Spain's rating. U.S. equities temporarily trimmed gains and other commodities dropped. The heavyweight materials sector, which includes gold miners, sank 1.2 percent. Losses were led by top gold producers Barrick Gold, down 3.2 percent to C$39.74, Goldcorp Inc , off 3.1 percent at C$37.15, and Yamana Gold, which dropped 2.5 percent to C$14.96. "The market is trying to climb a wall of worry," said Irwin Michael, portfolio manager at ABC Funds, which has $1 billion in assets under management. "People are concerned with the Greek situation spreading and it looks like it might have spread to Spain." Euro zone debt crisis fears increased after Spanish 10-year borrowing costs neared the 7 percent danger level after the government, struggling to sort out its finances, proposed putting sovereign debt into the struggling lender, Bankia. Reports that China was planning a new round of stimulus spending to boost lending and growth cheered stock markets and briefly boosted oil prices, which later slipped on the Spain downgrade and Middle East supply worries. Despite the drag from gold miners, seven of Canada's 10 main sectors finished higher. Oil and gas firms led the gains, up 0.9 percent. Cenovus Energy climbed 2.2 percent to C$33.11, Suncor Energy was up 1 percent at C$29.19, and Talisman Energy jumped 3.2 percent to C$11.09. In related news, Ithaca Energy shares plunged more than 35 percent to C$1.83 after the oil and gas producer said it ended talks with all parties related to an acquisition of the company. "The Canadian market has been underperforming for a while, because the commodities sector has been hammered," said Brendan Caldwell, chief executive of Caldwell Investment Management Ltd. The Toronto Stock Exchange's S&P/TSX composite index closed up 43.15 points, or 0.4 percent, at 11,609.30, retreating after hitting a two-week high at 11,687.71. Canadian financial issues, up 0.9 percent, shook off euro zone debt fears on good second-quarter earnings results from Bank of Nova Scotia. Scotiabank's shares jumped 2.2 percent to C$51.93 after Canada's No. 3 bank said its second-quarter operating profit rose 16 percent as international banking and lending profits grew. "At some point the world has to move beyond Europe," said Caldwell. "It's mentally written off Greece. It probably hasn't written off Spain, Italy and Portugal yet." Canadian railway shares also helped boost gains. Canadian National Railway was up 2.9 percent to C$84.30 after the country's largest railway operator said on Monday its 210 train dispatchers had ratified a new collective bargaining agreement. Canadian Pacific Railway jumped 1.7 percent to C$76.80 after the Canadian government said it will force CP's 4,800 striking workers back to work with fast-track legislation aimed at restoring rail service by Thursday. In other company news, shares of Viterra Inc edged down 0.2 percent to C$16 after shareholders of Canada's largest grain handler voted overwhelmingly on Tuesday in favor of a C$6.l billion ($5.9 billion) friendly takeover bid by Swiss commodities trader Glencore International Plc.