Given an array of event record strings records, implement a function that returns a new array containing only valid transformed records. Each input string has the form "key:value". A record is valid if it contains exactly one colon, the key is non-empty after trimming spaces, and the value is non-empty after trimming spaces. For each valid record, return it as "KEY=value", where the key is uppercased and duplicate keys keep only their last valid value while preserving the key's first appearance order.
def transform_records(records):