A serving prisoner accused of stabbing an imam five times in the head and neck has denied attempted murder.