Strange as it may seem because of the limited distance, the journey between Trieste and Ljubljana is rather tortuous and complicated, but there surely is a connection between Italy and Slovenia.
As you can find in this link, you go to Gorizia by train, then you need to catch a bus or a taxi to reach Nova Gorica in Slovenia, from where you will catch another train to Jesenice and finally to Ljubljana.
A different itinerary will take you to Gorizia by train and then to Nova Gorica by bus or taxi, then you take another train to Sezana, hence change to Divaca and finally to Ljubljana. This way you have to catch a series of means of transport, but the whole journey should last only 5 hours.
I suppose that you could travel faster if you chose to travel by coach, but I couldn't find reliable information about this.
EDIT : I'm sorry, but the correct page disappears whenever I try to link it. It is however to be found on www.reiseauskunft.bahn.de, then fill in the details of your request.