Hi there,
Might be able to help you but not 100% sure I understand your problem.
The thing that's confusing me is:
id|category_id|attribute_name|attribute_type
id|attribute_id|attribute_value
What are these two tables?
Can you give us some example data displayed in the sort of hierachy you're looking for?
Paul.
PS You may just be looking for a many-to-many relationship. That is, you have two tables: category, attribute where categories can have any number of attributes, but attributes can be associated with any number of categories. Is that it?