If you are in the AA or RAC, call them out if it happens away from home, they might do a scan and give you the code numbers or reason for failing , then you may be able to tackle it yourself, if not you are armed with whats wrong.
Sounds like the sort of thing that would happen to a petrol.
What about loose or worn wires to sensors or the fuel system, pump etc.
Starts ok from cold, but problems when warmed up. Sounds more electrical than mechanical.
A faulty Air Flow Sensor would tend to prevent revving much over 2.5k, but doubt if it would cause it to cut out. You could try unplugging it and see if it makes any differance, you might get black smoke, but if it revs freely with it disconnected it might have a bearing on it. These cost about £100 or more ( £75, 10 years ago for a British car) so not the sort of thing to try willy nilly, in case its that, but ends up as not ( unlike the dealers who keep replacing parts till they get it right).