All pastes #2133968 Raw Edit

Mine

public text v1 · immutable
#2133968 ·published 2012-03-30 12:22 UTC
rendered paste body
<div class="span12">
	<h4>Andrew's:</h4>
	<div class="well">
		<div class="well">
			<pre class="prettyprint linenums">
			&lt;xsl:value-of select="count(//customers/customer)"/&gt;
			</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">
				&lt;xsl:variable name="totalprice" select="sum(//products/product/price)" /&gt;
				&lt;xsl:variable name="totalproducts" select="count(//products/product)" /&gt;
				Average Price: £&lt;xsl:value-of select="substring($totalprice div $totalproducts,1,4)" /&gt;
			</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>