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:strip-space elements="*"/>
<xsl:key name="kFollowingChild1" match="*[not(self::Child1)]"
use="generate-id(preceding-sibling::Child1[1])"/>
<xsl:template match="Parent">
<TransformedXML>
<xsl:apply-templates/>
</TransformedXML>
</xsl:template>
<xsl:template match="Child1">
<Child>
<xsl:for-each select=".|key('kFollowingChild1', generate-id())">
<xsl:attribute name="attribute{position()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
</Child>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
when applied on the provided (corrected many times to become well-formed!) XML document:
<Root>
<Parent>
<Child1>A</Child1>
<Child2>B</Child2>
<Child1>X</Child1>
<Child2>Y</Child2>
</Parent>
</Root>
produces the wanted, correct result:
<TransformedXML>
<Child attribute1="A" attribute2="B"/>
<Child attribute1="X" attribute2="Y"/>
</TransformedXML>