Extract this if in to a separate method (processGlobalReferencesInElements), then remove processElement and call processGlobalReferencesInAttributes and processGlobalReferencesInElements