Is there a formal way to aggregate the Web of Science Categories?
Both Web of Science Categories and Essential Science Indicators are journal-level categorizations (with some reclassification of papers in multidisciplinary journals going on in Essential Science Indicators), with the difference that each journal can belong to multiple Web of Science Categories but only to one Essential Science Indicator category. This usually means that individual papers within a journal (at least within the same issue or year) will be assigned to the same Web of Science Categories (one or many) and also to the same Essential Science Indicators category. By mapping the Essential Science Indicators categories of journals (found here) onto papers you will therefore automatically get an aggregation. 

However, since journals (and papers) can have multiple Web of Science Categories attached to them (without any prioritization of what is the "main" category), you cannot have a simple one-to-one mapping between them, at least not without some further work.