Add transform to document before index

Closes #6566
I'll have another look.  The code in this class looked a bit copy and paste-y if I recall and I was trying to be careful.  I'll do something along these lines.