I\'ve got an extremely long XML file, like
context1
test1
If the OP's provided XML is representative of his/her question (and the 2nd inside each element should be removed), then Muenchian Grouping isn't necessary:
XSLT:
When run against the provided XML:
context1
test1
context1
context2
test2
context2
...the desired result is produced:
context1
test1
context2
test2