I think you want a new item list consisting of
- The first level of certain hierarchical items
- All other items, split at a period
- Combined together to remove duplicates.
- Then sorted
If so, then this template does it.
Code:
program:
g = field('#genre');
stripped_hierarchies = list_re_group(g, ',', '.',
'^(Fanfiction|Documentation and Manuals)($|\..*$)',
'{$}', '');
split_hierarchies = re(stripped_hierarchies, '\.', ',');
cleaned = list_union('', split_hierarchies, ',');
sorted = list_sort(cleaned, 0, ',')
The order of arguments to list_union is important. The function checks for duplicates while adding the second list to the first. It doesn't remove existing duplicates from the first. By passing an empty list as the first list, duplicates in the second list are removed as they are added to the first.
EDIT: added list_sort to the template.