I'm new to XSLT, I need to add all the price values. But the price values in XML have '-' and also no values and while doing sum I'm getting NaN. So i tried the below XSL, but still I'm unable to achieve my result.
Below is a sample XML
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Edited by XMLSpy® -->
<root>
<qwe>
<value>+1</value>
</qwe>
<qwe>
<value>20</value>
</qwe>
<qwe>
<value>-</value>
</qwe>
<qwe>
<value>30</value>
</qwe>
<qwe>
<value>-0</value>
</qwe>
<qwe>
<value/>
</qwe>
<qwe>
<value>8</value>
</qwe>
</root>
This is the XSL I'm trying to use:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" >
<xsl:template match="/">
<html>
<body>
<h2>My qwe Collection</h2>
<xsl:for-each select="root/qwe">
<xsl:variable name="len" select="replace(value,'-','0')" />
<xsl:variable name ="asd" select="sum(//value[number(.)=number(.)])"/>
sum: <xsl:value-of select="$asd"/><br/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Expected Result:
sum:59