This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SOLUTION - PROGRAM MANAGEMENT - How to sum of property over the ITEM Type

AbhishekSrivastava - Friday, October 7, 2016 7:26 AM:

Hi Friends,

If i want to count Items on Item Type then i have a code.

<xsl:stylesheet version="1.0" xmlns:xsl="www.w3.org/.../Transform">
 <xsl:output method="xml" omit-xml-declaration="yes"/>
 <xsl:template match="/"><Result><xsl:value-of select="count(//Item[@type='MACHINE ENTRY'])"/></Result></xsl:template>
</xsl:stylesheet>

Count is successful.

If I have a property name machine_hours and I want to sum machine_hours, so What changes required on above code.

Thanks in Advance

Abhishek Srivastava



edonahue - Monday, October 10, 2016 1:09 PM:

Hi Abhishek,

The XSLT you've provided counts the items of type "MACHINE ENTRY" using the standard XPath count() function. Similarly, you can use the standard XPath sum() function to sum property values from the result. 

Example:

<xsl:value-of select="sum(//Item[@type='MACHINE ENTRY']/machine_hours)"/>

Sum function documentation: https://msdn.microsoft.com/en-us/library/ms256160(v=vs.110).aspx