Have a look at the solution below
The Main/Sub category are both modeled as seperate entities and the Sub_Main association determines which subcategory belongs to which main categories.
The selectionhelper entity is used to pick a main and subcategory
On the page you can use reference selectors, to pick the main and sub category.
Filter on sub reference selector
On the sub reference selector you need to apply an xpath filter, such that only the subcategories associated with the selected main category is shown.
Refere the folloing link, it is in detail
Desgin you Domain model as like this and can add some data by assocaiting each and based on x-path you can show it in the client side