Given an $n\times n$ real diagonal matrix $D$ and an $m\times m$ real diagonal matrix $W$ (where $n\geq m$) with $\text{tr}(W^2)=1$, consider the following optimization problem in $X \in \mathbb{R}^{n \times m}$
$$\begin{array}{ll} \text{minimize} & \text{tr}\!\left((XW)^TD\,(XW)\right)\\ \text{subject to} & X^T X = I_m\end{array}$$
In the "equal-weighted" case $W=(I_m/m)^{1/2}$, this reduces to a standard Rayleigh quotient minimization problem. But in the more general case, setting up and solving the Lagrangian is causing some difficulties.
My current approach: Rewrite the constraint as $W^TX^TXW = W^2$, then set up the Lagrangian
$$\mathcal{L}(X,\Lambda) = \text{tr}\!\left((XW)^TD\,(XW)\right) + \text{tr}\!\left(\Lambda(W^2-W^TX^TXW)\right)$$
The first term enters into the first-order condition as $2DXW^2$, but I'm having trouble differentiating the second term since this formulation doesn't appear in any of the "cookbooks."
I have a hunch that given the orthonormality constraint $X^TX = I_m$, the solution doesn't depend on the matrix $W$ (so that one solution is given by $X$ equal to the first $m$ columns of $I_n$, since these can be taken as the eigenvectors for the diagonal matrix $D$), but am not positive. Any help appreciated.