I generated by a for each the following field: 214.2+428.4+end
I have used substring-before(prices,\'+end\') but this is a string.
Any ideas how I can take the 2
If the string contains a valid XPath expression (as it does in your example) then you need the ability to dynamically evaluate XPath expressions. This is not a standard feature of XSLT 1.0, however:
Alternatively, if you know that the string contains a sequence of numbers separated by plus signs, then you could write a recursive template to extract the tokens, convert them to numbers, and sum them. Or if it's always two numbers, then you don't even need recursion.
As so often happens, it's not enough to have one example of the input your program has to handle; we need to know what the set of all possible inputs is.
I would suggest you try it this way:
XSLT 1.0
<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:strip-space elements="*"/>
<xsl:template match="/items">
<xsl:variable name="subtotals">
<xsl:for-each select="item">
<amount>
<xsl:value-of select="price * quantity"/>
</amount>
</xsl:for-each>
</xsl:variable>
<total>
<xsl:value-of select="sum(exsl:node-set($subtotals)/amount)"/>
</total>
</xsl:template>
</xsl:stylesheet>
Applied to your example input, the result will be:
<?xml version="1.0" encoding="UTF-8"?>
<total>64.6</total>