I know this question already has an accepted answer, but it always makes me cringe when I see hard coded solutions like this.
Better to to try to sum up all existing attributes, than to use their specific names.
What if you want to add
attr4
and
attr5
later?
Then you have to change your code to work for that scenario.
The solution below only works if you want to get the sum of all existing attributes.
Example XML
<root>
<element attr1="10" attr2="20" />
<element attr1="10" attr2="20" attr3="30" />
<element attr1="10" attr2="20" attr3="30" attr4="40" attr5="50" />
</root>
XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="text" indent="no" />
<xsl:template match="root">
<xsl:apply-templates select="element" />
</xsl:template>
<xsl:template match="element">
Attribute Sum = <xsl:value-of select="sum(@*)" />
</xsl:template>
</xsl:stylesheet>
Output
Attribute Sum = 30
Attribute Sum = 60
Attribute Sum = 150