Hi,
In my opinion there is certainly a logic for coding. I only wonder how your DataSource looks like. Which fields are available, e.g. to determine the exact position in the hierarchy.
Please give more details on the source data.
Best regards,
Sander