<?xml version='1.0' encoding='utf-8' ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output method="html" indent="yes"/>
	<xsl:template name="Max">
	
		<!--This template will recursively -->
		<!--determine the maximim value in a nodeset -->
		
		
		<xsl:param name="list" />
		<xsl:param name="nMax" select="'0'"/>

		<xsl:choose>
			<xsl:when test="$list">

				<!-- Store the remaining list into a variable for subsequent -->
				<!-- recursive calls to this template 				       -->	
				<xsl:variable name="remainingList" select="$list[position() != 1]" />

				<!-- Calculate the new minimum value.  The value is set to   -->
				<!-- the currently passed in value, or the value in the node -->
				<!-- set, whichever is lower        				       -->	
				<xsl:variable name="nNewMax">
					<xsl:choose>
						<xsl:when test="$list[1] &gt; $nMax">
							<xsl:value-of select="$list[1]"	/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$nMax"	/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>

				<!-- Recursively call the current template with the newly 	 -->
				<!-- calculated minimum value								 -->
				<xsl:call-template name="Max">
					<xsl:with-param name="list" select="$remainingList"/>
					<xsl:with-param name="nMax" select="$nNewMax"/>
				</xsl:call-template>

		</xsl:when>

		<xsl:otherwise>
			<!-- If you have hit this section in the template, it indicates -->
			<!-- that no more elements need to be processed and that we	   -->
			<!-- return the maximum value instead of making any further     -->
			<!-- recursive calls 													   -->
			<xsl:value-of select="$nMax" />
		
		</xsl:otherwise>		
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>
