A typical transaction has one or more inputs and one or more outputs. Since there is no amount specified for inputs, the rule is that ALL of the inputs is always transferred. Any discrepancy between the value contained in the inputs and the total value of the outputs is lost forever.
When a transaction is first submitted there may be a discrepancy between the values of the inputs and outputs. The miner assembling the block may redirect that unaccounted for difference to themselves or any address they wish, called a "transaction fee", however my question is how do they do this?
It would seem the only way to do this would be to add new output to the transaction and new script to send the value to the output. So in other words the miner would change the transaction from the form submitted by the original poster, to a new form including the fee transmittal.
However, isn't the transaction hashed to prevent someone from altering it? If a miner can alter it, why not alter it to just direct all the input to themselves?