I'm assuming the structure output here is required for your Javascript accordion widget to work.
It may be possible to specify the id/html of the accordion container through Javascript parameters. If not a library like jquery ui (http://jqueryui.com/accordion/) may be more useful if you are adamant you need valid HTML.
Alternatively just leave it as it is as most browsers would not have a problem parsing that HTML and displaying it as intended.