XPath problems with using last() predicate

I tried to select some data using Xpath expression like that:
//*[@class="tablebg"][position() > 1 and position() < last()]

The problem is in algorythm of "last()" expression.

"last()" is selecting two last elements.

"last()-1" is selecting four last elements.

How to select last three elements? I already read all syntax at http://www.w3schools.com.

Please help.

Hi,

can you provide a snippet of the data you are executing this expression on?

Regards,

Alexander