Функция sum () в XSLT 1.0 может только суммировать числа, но не вычисления.Попробуйте это так:
XSLT 1.0 (+ EXSLT)
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="part_d">
<xsl:variable name="quantities">
<xsl:for-each select="description">
<q>
<xsl:value-of select="substring-before(., ' ')" />
</q>
</xsl:for-each>
</xsl:variable>
<total-quantity>
<xsl:value-of select="sum(exsl:node-set($quantities)/q)" />
</total-quantity>
</xsl:template>
</xsl:stylesheet>
Или, если вы предпочитаете:
XSLT
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="part_d">
<total-quantity>
<xsl:call-template name="add">
<xsl:with-param name="items" select="description"/>
</xsl:call-template>
</total-quantity>
</xsl:template>
<xsl:template name="add">
<xsl:param name="items" select="/.."/>
<xsl:param name="sum" select="0"/>
<xsl:choose>
<xsl:when test="$items">
<xsl:variable name="item" select="$items[1]" />
<xsl:variable name="n" select="substring-before($item, ' ')" />
<!-- recursive call -->
<xsl:call-template name="add">
<xsl:with-param name="items" select="$items[position() > 1]"/>
<xsl:with-param name="sum" select="$sum + $n"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$sum"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>