This stylesheet:
Output:
Note: Grouping by following separator
, adding last third level element for posible C
without following separator
.
Edit: More pull style, more schema agnostic, this stylesheet:
EDIT 2: More general solution (one thing I do not trust, ja!)
Note: Mostly a fine grained traversal. A floor hierarchy rule (in this case root element) copying itself and separator (dummy node for last group without following separator) passing remainder separators to process first child with enough following separators to process. A modified fine grained traversal identity rule, copying itself and again processing first child and following sibling with enough following separators to process. At last, a separator rule breaking the process.
Edit 3: Other more general solution, now with recursive identity rule
Edit 4: Now just the same as before but with key test instead of node set intersection.