You can use a key to select the nodes and group them by ID:
<xsl:key name="rows" match="Row" use="ID"/>
Then select each similar node only once, comparing to the key:
<xsl:template match="Rowset">
<xsl:copy>
<xsl:apply-templates select="Row[generate-id(.) = generate-id(key('rows', ID))]"/>
</xsl:copy>
</xsl:template>
To sum all the values you can use a XPath expression for each node you wish to sum:
sum(//Row[ID='S112']/ActualHours)
and use that in a template for each different ID.
Edit: a better solution (as suggested by @IanRoberts) is using the key we generated and selecting each based on the ID of the current node being processed:
sum(key('rows', ID)/ActualHours)
(The example above is applied in a Row
context.)
Here is a full stylesheet that uses these transformations and that you can use as a starting point:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="rows" match="Row" use="ID"/>
<xsl:template match="Rowset">
<xsl:copy>
<xsl:apply-templates select="Row[generate-id(.) = generate-id(key('rows', ID))]"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Row">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="ActualHours | NoOfMachine | MPerHour | TargetProduction | ActualProduction">
<xsl:variable name="tag-name" select="name()"/>
<xsl:copy>
<xsl:value-of select="sum(key('rows', ../ID)/*[$tag-name=name()])"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Name | ID | ProductCode">
<xsl:copy>
<xsl:value-of select="."/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>