There is a railways (in fact even several) between Italy and Slovenia, but they only carry freight at the moment. The main reason is that Trenitalia is not an easy company to cooperate with, and the Slovenian railways don't have the money to go on their own (like for example the German and Austrian railways have done) I have travelled from Ljubljana to Trieste when cross border trains were still running, but this was a few years ago.
Currently the options to get from Trieste to Ljubljana are:
- Direct bus.
- Bus to Sezana and train from there.
- Tram (it's quite an interesting tram actually) to Vila Oppicina. Taxi to Sezana from there. Then train.
www.bahn.de will give you info for trains from Sezana to Ljubljana.
www.autostazionetrieste.it has info about buses.
You can also go via Gorizia (and walk from the one station to the other) but that's a bit roundabout.
Update: Since the last timetable change there is again a train from Vila Opicina (above Trieste) to Ljubljana. So the trip now involves using the tram,bus or a taxi to get to Vila Opicina, where you can now board the train again. Lets hope this improves in the future.