SELECTING A TRANSISTOR  
These notes are just a guide. Don't let them over-ride a solution you know about. 
Sometimes ANY TRANSISTOR will do. Other times it must be absolutely correct. 

There are a lot of factors that determine the type of transistor in each part of a circuit and the answers to the problem cannot be described in 100 lines; but here are few tips:

LOW VALUES
If the circuit has low-voltage, low-frequency and low-current, almost any transistor will work. If any factor increases (such as if a coil is present), you will need to put more thought into the substitute.

VOLTAGE
There is one critical factor when deciding on the type of transistor for any location. It's the voltage rating. A transistor can get hot and even super-hot and survive, but it cannot withstand a high-voltage spike. Even if the spike is a millisecond or less! It will be instantly damaged. Sometimes you are lucky. If the transistor is robust, and has a high current capability, it may withstand the spike. 
A spike generally doesn't come from the circuit when it is working correctly, it comes when a fault develops, or when an outside influence is present. 
There are lot of components in a circuit to prevent or "arrest" a spike, and if these fail, the spike punctures the transistor. That's why the fault isn't always the transistor - it may be a faulty component. 
I had one situation where the tuning capacitor across the primary of an EHT transformer was faulty and allowed the transformer to produce a spike that punctured the driver transistor. After 5 transistors I finally worked out the fault! A very expensive repair!
If the transistor has a high collector-to-emitter voltage rating, it may survive the incident and this is one of the factors that must be considered when deciding on a substitute. In the repair above, the transistor was a 1,000v device but the spike was 2,000v!
In general, Philips transistors have a very low voltage rating (can be as low as 25 - 65v) whereas the Japanese equivalent can have a rating 90 - 250v. That's why you shouldn't replace Japanese types with Philips types.
In general, Japanese types are much more reliable than Philips types. By this we mean the 2SA, 2SB, 2SC etc types are more reliable. 
The types to be careful of are: BC, BD. They are only just acceptable for the job. This is only a general statement after fixing over 35,000 TV's etc.  

PIN-OUTS
Don't worry about the pin-out of a substitute, you can generally bend the leads to fit the replacement. However, if the transistor is a "high-hat" type, (such as TO-3 - or the smaller version TO-66) the leads cannot be rearranged very easily, but fortunately the pin-out for these devices is almost always the same. It is only the "bolt-down" types ( TO-126, TO-220) that can sometimes have different pin-outs. 

HEATSINKING
When fitting plastic or mica insulation between a transistor and heatsink, you must add a very fine smear of thermal compound. This compound will improve the heat transfer at least 200% and reduce the temperature of the transistor. But the main problem is a dry connection will allow the transistor to heat up and melt or buckle or burn the plastic sheet and it may eventually fail due to carbonising and allow a voltage path to track between transistor and ground.  

COLLECTOR-EMITTER VOLTAGE ON "TURN-ON"

Another piece of knowledge that is rarely mentioned is the voltage between the collector-emitter terminals when the transistor is turned on. Some new transistors (such as ZTX 851) have a C-E voltage of less than 0.05v, whereas the normal voltage can be 0.15v to 0.35v. The lower voltage enables the transistor to drive the circuit harder but more important it creates less heat in the transistor (from 60% to nearly 85% less). A normal transistor will get 3 - 7 times hotter and blow-up! - even though the normal transistor has the required current and voltage rating!
In one oscillator circuit the ZTX 851 produced an output 20% higher than any other transistor, merely because it was able to drive the circuit harder. See the circuit HERE.

THE GAIN
In general, you don't have to worry about the gain of a transistor. If one type has a gain of 250 and another has a gain of 450, the second one will not necessarily work better. The specified gain is only an average and it is the DC current gain. Very few circuits work in a purely DC situation and so the value of gain is a valueless parameter. The first transistor mentioned above may have an actual gain as low as 150 or as high as 350 and the second may have a gain of 250 or 500. When a transistor is placed in a circuit with biasing components, the gain reduces considerably. Both the transistors above may produce exactly the same stage gain. In general you should only allow a stage-gain of 70 - 150 when a transistor is placed in a circuit - and to be more realistic I only allow 70 - 100 for any stage I am creating. The stage-gain will also depend on the voltage of the rail. 

HOT
If you cannot hold a transistor in your fingers for more than 30 seconds, it is getting too hot. Otherwise it will last indefinitely. This is the amazing capability of silicon transistors. Obviously, you should look into redesigning the circuit so that it wastes less power, but a transistor can sit comfortably at finger-hot temperature for a life-time. For example, one TV circuit had metal can video transistors with heatfins and the transistors were too hot to touch. The next model had a different circuit with tiny plastic transistors and they ran totally cold! It's all due to the skill of the design engineer.

EXOTIC TYPE-NUMBERS
Don't be fooled by exotic type-numbers in a design. If you find a transistor with a "special type-number" start by substituting it with the cheapest type available. Test the circuit and see if it works. Some manufacturers like to slow down the possibility of a repair by specifying their own types. Very rarely do these provide any special parameters. 

ONE LAST TRICK 
When you get a product in for repair, the first things to suspect are the electrolytics - not the transistors. Transistors are extremely reliable but electrolytics quite often dry out and cause the circuit to fail. Electrolytics can be tested with an in-circuit electrolytic tester and if you find two or three electros have dried out, it is best to replace them ALL. I know this is a hassle but I had a fax machine with faulty electros and as I went through each electro, one fault after another was cured.  

 
 - Colin