Imagine you have a two noded beam in space, defined by extreme nodes 1 and 2.

Image is owned by Jean-Marc Battini.
To simplify, initially, the longitudinal axis of the beam, local x axis, defined by the unit vector of the line that connects the nodes 1 and 2 , is coincident with the X axis of the global coordinate system. I also know the original directions of local y and z axis.
Now assume that the beam rotated, with independent rotations in nodes 1 and 2. I know the rotations along global X, Y and Z axis of nodes 1 and 2.
How can I know the updated vectors that define the new local coordinate system of the beam, x, y and z based on the original vectors and the rotations about the global axis at each node? Or, as per figure above, how can I know the rotation matrices Rr, R1 and R2 based on the rotation matrix R0 and rotation values of nodes 1 and 2?
Thanks!