<div class="span12">
<h4>Andrew's:</h4>
<div class="well">
<div class="well">
<pre class="prettyprint linenums">
<xsl:value-of select="count(//customers/customer)"/>
</pre>
<div>
This XPath query prints a number corresponding with the number of <i>customer</i> elements in the <i>customers entity</i>.
The XSLT function <code>count(a)</code> returns a numerical count of all nodes in the node-set argument <code>a</code>.
</div>
<br />
<div>
The example output would be:
<div class="well">
<span><i>Total: </i>3</span>
</div>
</div>
</div>
<div class="well">
<pre class="prettyprint linenums">
<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)" />
</pre>
<div>
This XPath query prints the average <i>price</i> of a <i>product</i> in the <i>products entity</i>.
The XSLT function <code>sum(a)</code> returns the summation of all nodes in the node-set argument <code>a</code>.
The <code>count(b)</code> function returns the number of nodes in the node-set argument <code>b</code>.
The output from the sum function is divided by the number of products to get the average cost.
The <code>substring(c)</code> function crops the output to only show 3 significant figures of input <code>c</code>.
</div>
<br />
<div>
The example output would be:
<div class="well">
<span><i>Average Price: </i>£1.96</span>
</div>
</div>
</div>
</div>
</div>