<xsl:value-of select="count(//customers/customer)"/>
This XPath query prints a number corresponding with the number of customer elements in the customers entity.
The XSLT function count(a) returns a numerical count of all nodes in the node-set argument a.
The example output would be:
Total: 3
<xsl:variable name="totalprice" select="sum(//products/product/price)" />
<xsl:variable name="totalproducts" select="count(//products/product)" />
Average Price: £<xsl:value-of select="substring($totalprice div $totalproducts,1,4)" />
This XPath query prints the average price of a product in the products entity.
The XSLT function sum(a) returns the summation of all nodes in the node-set argument a.
The count(b) function returns the number of nodes in the node-set argument b.
The output from the sum function is divided by the number of products to get the average cost.
The substring(c) function crops the output to only show 3 significant figures of input c.
The example output would be:
Average Price: £1.96