Canonical transformation and stabilization of generalized Hamiltonian systems