<!-- Add up all the amountPaid properties below $currentPage -->
<xsl:variable name="total" select="sum($currentPage//amountPaid)" />
<p>Total paid to date: <xsl:value-of select="$total"/></p>
Are there likely to be "wrong" data in those fields? E.g., someone entered "$12.80" or "fifty quid" - then you'd probably need to sanitize the data a bit...
getting total value of item in a loop
Hi all,
I have some XSLT that loops and displays sub pages from a parent. I need to calculate the total value of one amountPaid and display it like this:
<xsl:for-each select="$currentPage/descendant::* [@isDoc]">
<li>
<p>Date Paid: <xsl:value-of select="umbraco.library:FormatDateTime(datePaid, 'MMMM d, yyyy')"/></p>
<p>Amount Paid: £<xsl:value-of select="amountPaid"/></p>
<p>Notes: <xsl:value-of select="otherInformation"/></p>
</li>
</xsl:for-each>
<xsl:variable name="total" select="sum(preceding-sibling::$currentPage/descendant::*) + amountPaid"/>
<p>Total paid to date: <xsl:value-of select="@total"/></p>
I know the xslt for to calculate the total is incorrect. Can anyone help in the correct xslt to acheive the total please?
Thanks!
I tried this but it returns '0'
Total paid to date: £<xsl:value-of select="sum(/*/*/amountPaid)"/>
Hi Roger,
A simple variable should do it:
Are there likely to be "wrong" data in those fields? E.g., someone entered "$12.80" or "fifty quid" - then you'd probably need to sanitize the data a bit...
/Chriztian
Hi Chriztian, There will only be numeric entries with 2 decimal places.
Is there a way to add the decimal places to the solution you have provided?
Thanks for the help
Roger
I had a crack at it the format-number seems to work
<xsl:value-of select="format-number($total,'0.00')"/>
Thanks for the help Chriztian
is working on a reply...