This question requires a little bit more detailed answer than just pointing to a good Muenchian Grouping source.
The reason is that the needed grouping requires to identify both the names of all children of an "ele[SomeString]" element and their parent. Such grouping requires to define a key that is uniquely defined by both unique sources, usually via concatenation.
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:key name="kElByName" match="*"
use="concat(generate-id(..), '+',name())"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[starts-with(name(), 'ele')]">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select=
"*[generate-id()
=
generate-id(key('kElByName',
concat(generate-id(..), '+',name())
)[1])
]"
/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
when applied on this XML document:
<Root>
<ele1>
<child1>context1</child1>
<child2>test1</child2>
<child1>context1</child1>
</ele1>
<ele2>
<child1>context2</child1>
<child2>test2</child2>
<child1>context2</child1>
</ele2>
<ele3>
<child2>context2</child2>
<child2>test2</child2>
<child1>context1</child1>
</ele3>
</Root>
produces the wanted result:
<Root>
<ele1>
<child1>context1</child1>
<child2>test1</child2>
</ele1>
<ele2>
<child1>context2</child1>
<child2>test2</child2>
</ele2>
<ele3>
<child2>context2</child2>
<child1>context1</child1>
</ele3>
</Root>