First, an html table with manually expressed structure. Rows visibility should be coherent. If collapsed, following branch rows should be hidden.

A B C
A.1 B.1.1 C.1.1
B.1.2 C.1.2
B.1.3 C.1.3
A.2 B.2.1 C.2.1
A3 B C

Next, a script constructed one. Please note the markup.

The same, but with PK compression, as intended by markup, not value.

With different style.

Let CCTT to handle structure, guessing from records' stream.

This schema is important: it correspond to join and selection by ordered PK.