It is silly, but here's my XSLT that sums cost elements and replaces it with a total:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="add"> <total><xsl:value-of select="sum(cost)"/></total> </xsl:template> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
Any non-add or cost element will be returned unchanged.
The element can exist in any context.