Fix: Corrected transposeHeaderElements to allow header elements anywhere in the document