when a block is mined, an output is created, outputs can only be spent once. a bitcoin transaction is just a list of existing outputs (inputs) and new outputs to create (outputs). each output is created with a lock script, to spend the output you must provide the unlock script which normally contains at least a signature and a public key
returning the output that corresponds to the unwanted transaction should do