Take the following utility function:
$$
\prod_{s \in S} \left(\sum_{i \in N} x_{i,s}^{\frac{\sigma_s-1}{\sigma_s}} \right)^{\frac{\sigma_s}{\sigma_s-1}\mu_{s}}
$$
Which is a CES nested in a Cobb-Douglas.
Consider the sub-utility function:
$$
Q_{s} = \left(\sum_{i \in N} x_{i,s}^{\frac{\sigma_s - 1}{\sigma_s}}\right)^{\frac{\sigma_s}{\sigma_s - 1}}.
$$
Then we can re-write the utility function succinctly as:
$$
U = \prod_{s \in S} Q_s^{\mu_s}
$$
To solve the utility maximisation problem. Notice that $U$ is separable in the subgroups. As such, we can solve the problem using two stage budgeting.
- In the first step, we can determine the optimal allocation within each subgroup $s$ by maximize the sub-utility functions $Q_s$ given the total expenditure $E_s$ given on each subgroup $s$.
- In the second step, we determine the optimal allocation of income across each subgroup $s$.
For Step 1, we solve the following problem:
$$
\max\left(\sum_{i \in N} x_{i,s}^{\frac{\sigma_s - 1}{\sigma_s}}\right)^{\frac{\sigma_s}{\sigma_s - 1}} \text{subject to } \sum_{i \in N} p_{i,s} x_{i,s} = E_s.
$$
This is a CES utility function. The first order condition gives:
$$
Q_s \frac{x_{i,s}^{-\frac{1}{\sigma_s}}}{\sum_{w \in N} x_{w,s}^{\frac{\sigma_s - 1}{\sigma_s}}} = \lambda p_{i,s}.
$$
Then:
$$
x_{i,s} = \lambda^{-\sigma_s} p_{i,s}^{-\sigma_s} \left(\frac{\sum_w x_{w,s}^{\frac{\sigma_s - 1}{\sigma_s}}}{Q_s}\right)^{-1\sigma_s}
$$
Multiplying by $p_{i,s}$ and adding over all $i \in N$ gives:
$$
\begin{align*}
E_s = \sum_{i \in N} p_{i,s} x_{i,s} &= \lambda^{-\sigma_s} \left(\frac{\sum_w x_{w,s}^{\frac{\sigma_s - 1}{\sigma_s}}}{Q_s}\right)^{-\sigma_s} \sum_{i \in N} p_{i,s}^{1 - \sigma_s}\\
&= \lambda^{-\sigma_s} \left(\frac{\sum_w x_{w,s}^{\frac{\sigma_s - 1}{\sigma_s}}}{Q_s}\right)^{-\sigma_s} P_s^{1 - \sigma_s}
\end{align*}
$$
Where $E_{s} = \sum_{i\in N} p_{i,s} x_{i,s}$ and $P_{s}^{1- \sigma_s} = \sum_{i \in N} p_{i,s}^{1- \sigma_s}$.
Then:
$$
x_{i,s} = E_{s} \frac{p_{i,s}^{-\sigma_s}}{P_{s}^{1-\sigma_s}} \tag{1}
$$
Let's compute the value of $Q_s$:
$$
\begin{align*}
&x_{i,s}^{\frac{\sigma_s-1}{\sigma_s}} = E_{s}^{\frac{\sigma_s-1}{\sigma_s}} \left(\frac{p_{i,s}^{-\sigma_s}}{P_{s}^{1 -\sigma_s}}\right)^{\frac{\sigma_s-1}{ \sigma_s}},\\
\to &\sum_{i \in N} x_{i,s}^{\frac{\sigma_s-1}{\sigma_s}}= E_{j,s}^{\frac{\sigma_s-1}{\sigma_s}} \left(\frac{1}{P_{s}^{1- \sigma_s}}\right)^{\frac{\sigma_s-1}{\sigma_s}} \sum_{i \in N} p_{i,s}^{(1-\sigma_s)},\\
\to& \sum_{i \in N} x_{i,s}^{\frac{\sigma_s-1}{\sigma_s}} = E_{s}^{\frac{\sigma_s-1}{\sigma_s}} P_{s}^{\frac{1 - \sigma_s}{\sigma_s}}\\
\to & \left(\sum_i x_{i,s}^{\frac{\sigma_s-1}{\sigma_s}}\right)^{\frac{\sigma_s}{\sigma_s-1}} = E_{s} P_{s}^{-1}\\
\to& P_{s} Q_s = E_{s}.
\end{align*}
$$
This shows that the price index $P_s$ and the quantity index $Q_s$ are exact price and quanty indices for this subgroup (as is expected as we were maximising a CES utility function).
Let's now go to step 2. Notice that the budget constraint can be rewritten as:
$$
E = \sum_{s} E_s = \sum_s P_s Q_s.
$$
We want to determine $E_s$ to maximize:
$$
U = \prod_{j \in S} Q_{s}^{\mu_{j,s}} \text{ s.t. } \sum_s P_{s} Q_{s} = E.
$$
This is a simple Cobb-Douglas utility function. As such, we know that expenditure shares are proportional to income:
$$
P_s Q_s = E_s = \frac{\mu_s}{\sum_w \mu_w} E
$$
Finally, substitute this into the equation $(1)$:
$$
x_{i,s} = \frac{\mu_{s}}{\sum_w \mu_w} E \frac{p_{i,s}^{-\sigma_s}}{P_{s}^{1- \sigma_s}}
$$