I have multiple Rows data in my XML like this -
English1
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="kRowById"
match="ROW[not(@TYPE='TOTAL')]" use="@ID"/>
<xsl:template match="ROW[@TYPE='TOTAL']">
<xsl:copy-of select="."/>
<xsl:copy-of select="key('kRowById', @ID)"/>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
when applied on the provided XML (wrapped into a single top element to be made a well-formed XML document):
<t>
<ROW TYPE="SPECIFICATION" ID="1">
<R1>English1</R1>
</ROW>
<ROW TYPE="SPECIFICATION" ID="1">
<R1>Maths1</R1>
</ROW>
<ROW TYPE="TOTAL" ID="1">
<R1>Code1</R1>
</ROW>
<ROW TYPE="SPECIFICATION" ID="2">
<R1>English2</R1>
</ROW>
<ROW TYPE="SPECIFICATION" ID="2">
<R1>Maths2</R1>
</ROW>
<ROW TYPE="TOTAL" ID="2">
<R1>Code2</R1>
</ROW>
</t>
produces the wanted result (in which the wanted elements are re-ordered:
<ROW TYPE="TOTAL" ID="1">
<R1>Code1</R1>
</ROW>
<ROW TYPE="SPECIFICATION" ID="1">
<R1>English1</R1>
</ROW>
<ROW TYPE="SPECIFICATION" ID="1">
<R1>Maths1</R1>
</ROW>
<ROW TYPE="TOTAL" ID="2">
<R1>Code2</R1>
</ROW>
<ROW TYPE="SPECIFICATION" ID="2">
<R1>English2</R1>
</ROW>
<ROW TYPE="SPECIFICATION" ID="2">
<R1>Maths2</R1>
</ROW>