To reduce conflicts, we deal with labels indirectly through a counter. The counter is increased before \getlabel and after ref. That is, this pair is assured consistency of a label. The separation between \GetLabel and \PutLabel is to allow the latter one into immediate arguments such as \HCode and \Tg.
\label sends its info to \getlabel. It insert a ‘<pageref name="#1">’ iff it is a target of a \pageref.