The electrical transformer in an x-ray machine serves the same purpose
as any transformer in any electrical device: it transforms the
voltage. It can be configured to step the voltage from low to high, or
from high to low, depending on the particular need.
If you go out on the street you'll see transformers mounted high up
on the wooden poles that hold power cables. These are made to step
voltage down. The power lines need to carry very high voltage current
in order to reduce loss over many miles of cable. But the necessary
voltage for this is way too high to be safe for use in homes, so the
transformer is used to step it down to a tolerable level for peoples'
In the case of an x-ray machine, the voltage will be actually be
stepped up considerably. This is because a high voltage is required to
accelerate electric charges (electrons) up to the energy of the x-rays
to the produced. The electrons are accelerated by the voltage, and
then allowed to slam into a metal target. This decelerates the
electrons and the kinetic energy energy is dumped into the electrons'
electric fields, which manifests itself as electromagnetic waves of
energy equal to that dumped into the fields. In other words, the high
energy waves are x-rays.