<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/2000/svg">
	<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" standalone="no"
                   doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
                   doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" />
    
	<!-- Variables used for the SVG graphical output -->
	<xsl:variable name="page_width" select="number(800)"/>
	<xsl:variable name="cells_per_row" select="number(5)"/>
	<xsl:variable name="horizontal_spacing" select="$page_width div $cells_per_row"/>
	<xsl:variable name="vertical_spacing" select="number(200)"/>
	<xsl:variable name="cell_width" select="number(120)"/>
	<xsl:variable name="cell_height" select="number(26)"/><!-- 26 -->
	<xsl:variable name="margin" select="number(20)"/>
	<xsl:variable name="uniqueStep_yOffset" select="number(40) + $cell_height"/>
	<xsl:variable name="uniqueStep_xOffset" select="$horizontal_spacing * 0.6 + 10"/>
	<xsl:variable name="line-style">stroke:rgb(46,92,163);stroke-width:2;fill-opacity:0;stroke-opacity:1</xsl:variable>
	<xsl:variable name="anchor_xOffset" select="number(120)"/>
	<xsl:variable name="anchor_yOffset" select="number(40)"/>
	<xsl:variable name="cell-x-margin" select="number(10)"/>
	<xsl:variable name="cell-y-margin" select="number(10)"/>
	
	<xsl:template match="/system-workflow-definition">
		<svg width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/2000/svg">
		    <defs>
		        <linearGradient id="blue_grad" x1="0%" y1="100%" x2="0%" y2="0%">
		            <stop offset="0%" style="stop-color:rgb(68,116,191); stop-opacity:1"/>
		            <stop offset="100%" style="stop-color:rgb(46,92,163); stop-opacity:1"/>
		        </linearGradient>
		        <linearGradient id="end_step" x1="0%" y1="100%" x2="0%" y2="0%">
		            <stop offset="0%" style="stop-color:rgb(68,191,116); stop-opacity:1"/>
		            <stop offset="100%" style="stop-color:rgb(46,163,92); stop-opacity:1"/>
		        </linearGradient>
		        <marker id="arrowhead" viewBox="0 0 10 10" refX="1" refY="5" markerUnits="strokeWidth" orient="auto" markerWidth="4" markerHeight="4">
            		<polyline points="0,0 10,5 0,10" fill="rgb(46,92,163)"/>
        		</marker>
		    </defs>
		  
			<!-- The completed 'loaded-steps' pseudo-array -->
		    <xsl:variable name="loaded-steps">
			    <xsl:call-template name="beginProcessingSteps">
			    	<xsl:with-param name="initial-step" select="@initial-step"/>
			    </xsl:call-template>
			</xsl:variable>
			
			<xsl:variable name="loaded-pointers">
				<xsl:call-template name="getLoadedPointers">
					<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
				</xsl:call-template>
			</xsl:variable>
			
			<xsl:comment>
				$loaded-steps: <xsl:value-of select="$loaded-steps"/>
				$loaded-pointers: <xsl:value-of select="$loaded-pointers"/>
			</xsl:comment>
			
			<xsl:comment>
				getOffset:
				<xsl:call-template name="getOffset">
					<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
					<xsl:with-param name="node-number" select="'9'"/>
					<xsl:with-param name="pointer-region" select="'top-left'"/>
					<xsl:with-param name="pointer" select="'t6'"/>
				</xsl:call-template>
			</xsl:comment>
			
			<xsl:call-template name="printLoadedSteps">
				<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
				<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
			</xsl:call-template>
		</svg>
	</xsl:template>
	
	<!--
		Returns a pseudo-array in format of: "(1){[||][t2,][||][]}" where t2 is the arrow pointing TO node with node-number 2
		f2 would be the arrow point FROM node-number 2.
	-->
	<xsl:template name="getLoadedPointers">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="loaded-pointers" select="'(1){[||][][||][]}'"/>
		<xsl:param name="node-number" select="number(1)"/>

		<xsl:variable name="node-exists">
			<xsl:call-template name="key_exists">
				<xsl:with-param name="pseudo-array" select="$loaded-pointers"/>
				<xsl:with-param name="key" select="$node-number"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:choose>
			<xsl:when test="$node-exists='true'">
				<xsl:variable name="node-content">
					<xsl:call-template name="getNodeByNumber">
						<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
						<xsl:with-param name="node-number" select="$node-number"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="node-pointers">
					<xsl:call-template name="getNodePointers">
						<xsl:with-param name="node-content" select="$node-content"/>
					</xsl:call-template>
				</xsl:variable>
				
				<!-- Add the next node's to-pointers/resulting from-pointers -->
				<xsl:call-template name="getLoadedPointers">
					<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
					<xsl:with-param name="loaded-pointers">
						<!-- Modified loaded-pointers array after adding toPointers to the current node-number -->
						<xsl:call-template name="add_toPointers">
							<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
							<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
							<xsl:with-param name="node-number" select="$node-number"/>
							<xsl:with-param name="node-pointers" select="$node-pointers"/>
						</xsl:call-template>
					</xsl:with-param>
					<xsl:with-param name="node-number" select="$node-number + 1"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$loaded-pointers"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		Returns the modified loaded-pointers.
		node-pointers, ie: "2]3]4]5]"
	-->
	<xsl:template name="add_toPointers">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="loaded-pointers"/>
		<xsl:param name="node-number"/>
		<xsl:param name="node-pointers"/>
		
		<xsl:variable name="current-node" select="substring-before($node-pointers, ']')"/>
		
		<xsl:choose>
			<!-- Base Case: -->
			<xsl:when test="$current-node=''">
				<xsl:value-of select="$loaded-pointers"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="add_toPointers">
					<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
					<xsl:with-param name="loaded-pointers">
						<xsl:call-template name="add_toPointer">
							<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
							<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
							<xsl:with-param name="from-node" select="$node-number"/>
							<xsl:with-param name="to-node" select="$current-node"/>
						</xsl:call-template>
					</xsl:with-param>
					<xsl:with-param name="node-number" select="$node-number"/>
					<xsl:with-param name="node-pointers" select="substring-after($node-pointers, ']')"/>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		Returns modified loaded-pointers.
	-->
	<xsl:template name="add_toPointer">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="loaded-pointers"/>
		<xsl:param name="from-node"/>
		<xsl:param name="to-node"/>
		
		<xsl:variable name="from-node-content">
			<xsl:call-template name="getNodeByNumber">
				<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
				<xsl:with-param name="node-number" select="$from-node"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="from-cell-position">
			<xsl:call-template name="getPosition">
				<xsl:with-param name="node-content" select="$from-node-content"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:variable name="to-node-content">
			<xsl:call-template name="getNodeByNumber">
				<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
				<xsl:with-param name="node-number" select="$to-node"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="to-cell-position">
			<xsl:call-template name="getPosition">
				<xsl:with-param name="node-content" select="$to-node-content"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:variable name="pointer-region">
			<xsl:call-template name="getPointerRegion">
				<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
				<xsl:with-param name="cell-position" select="$from-cell-position"/>
				<xsl:with-param name="pointer-node-number" select="$to-node"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:variable name="region-content">
			<xsl:call-template name="getPointerRegionContent">
				<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
				<xsl:with-param name="node-number" select="$from-node"/>
				<xsl:with-param name="region" select="$pointer-region"/>
			</xsl:call-template>
		</xsl:variable>
		
		<!-- Modified loaded-pointers array after inserting fromPointer in response to the toPointer made -->
		<xsl:call-template name="add_fromPointer">
			<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
			<xsl:with-param name="loaded-pointers">
				<!-- Modified loaded-pointers array after inserting toPointer -->
				<xsl:call-template name="setPointerRegionContent">
					<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
					<xsl:with-param name="node-number" select="$from-node"/>
					<xsl:with-param name="region" select="$pointer-region"/>
					<xsl:with-param name="new-content">
						<xsl:call-template name="insertPointer">
							<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
							<xsl:with-param name="cell-position" select="$from-cell-position"/>
							<xsl:with-param name="side">
								<xsl:choose>
									<xsl:when test="$pointer-region='left' or $pointer-region='right'">
										<xsl:value-of select="$pointer-region"/>
									</xsl:when>
									<xsl:when test="$pointer-region='bottom-left' or $pointer-region='bottom-mid' or $pointer-region='bottom-right'">bottom</xsl:when>
									<xsl:when test="$pointer-region='top-left' or $pointer-region='top-mid' or $pointer-region='top-right'">top</xsl:when>
								</xsl:choose>
							</xsl:with-param>
							<xsl:with-param name="pointers" select="$region-content"/>
							<xsl:with-param name="pointer" select="concat('t', $to-node)"/>
						</xsl:call-template>
					</xsl:with-param>
				</xsl:call-template>
			</xsl:with-param>
			<xsl:with-param name="to-node" select="$to-node"/>
			<xsl:with-param name="from-node" select="$from-node"/>
		</xsl:call-template>
	</xsl:template>
	
	<!--
		Returns modified loaded-pointers array
	-->
	<xsl:template name="setPointerRegionContent">
		<xsl:param name="loaded-pointers"/>
		<xsl:param name="node-number"/>
		<xsl:param name="region"/>
		<xsl:param name="new-content"/>
		
		<xsl:variable name="pointer-content">
			<xsl:call-template name="getNodeByNumber">
				<xsl:with-param name="loaded-steps" select="$loaded-pointers"/>
				<xsl:with-param name="node-number" select="$node-number"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:variable name="top-left">
			<xsl:choose>
				<xsl:when test="$region='top-left'">
					<xsl:value-of select="$new-content"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="getPointerRegionContent">
						<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
						<xsl:with-param name="node-number" select="$node-number"/>
						<xsl:with-param name="region" select="'top-left'"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="top-mid">
			<xsl:choose>
				<xsl:when test="$region='top-mid'">
					<xsl:value-of select="$new-content"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="getPointerRegionContent">
						<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
						<xsl:with-param name="node-number" select="$node-number"/>
						<xsl:with-param name="region" select="'top-mid'"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="top-right">
			<xsl:choose>
				<xsl:when test="$region='top-right'">
					<xsl:value-of select="$new-content"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="getPointerRegionContent">
						<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
						<xsl:with-param name="node-number" select="$node-number"/>
						<xsl:with-param name="region" select="'top-right'"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="right">
			<xsl:choose>
				<xsl:when test="$region='right'">
					<xsl:value-of select="$new-content"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="getPointerRegionContent">
						<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
						<xsl:with-param name="node-number" select="$node-number"/>
						<xsl:with-param name="region" select="'right'"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="bottom-right">
			<xsl:choose>
				<xsl:when test="$region='bottom-right'">
					<xsl:value-of select="$new-content"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="getPointerRegionContent">
						<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
						<xsl:with-param name="node-number" select="$node-number"/>
						<xsl:with-param name="region" select="'bottom-right'"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="bottom-mid">
			<xsl:choose>
				<xsl:when test="$region='bottom-mid'">
					<xsl:value-of select="$new-content"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="getPointerRegionContent">
						<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
						<xsl:with-param name="node-number" select="$node-number"/>
						<xsl:with-param name="region" select="'bottom-mid'"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="bottom-left">
			<xsl:choose>
				<xsl:when test="$region='bottom-left'">
					<xsl:value-of select="$new-content"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="getPointerRegionContent">
						<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
						<xsl:with-param name="node-number" select="$node-number"/>
						<xsl:with-param name="region" select="'bottom-left'"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="left">
			<xsl:choose>
				<xsl:when test="$region='left'">
					<xsl:value-of select="$new-content"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="getPointerRegionContent">
						<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
						<xsl:with-param name="node-number" select="$node-number"/>
						<xsl:with-param name="region" select="'left'"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		
		<xsl:call-template name="assignNodeContent">
			<xsl:with-param name="pseudo-array" select="$loaded-pointers"/>
			<xsl:with-param name="index" select="$node-number"/>
			<xsl:with-param name="new-content">
				<xsl:value-of select="concat('[', $top-left, '|', $top-mid, '|', $top-right, '][', $right, '][', $bottom-left, '|', $bottom-mid, '|', $bottom-right, '][', $left, ']')"/>
			</xsl:with-param>
		</xsl:call-template>
	</xsl:template>
	
	<!--
		side, ie: 'top', 'right', 'bottom', 'left'
		pointers, ie: "t6,f6,f10,"
		pointer, ie: "t4"
	-->
	<xsl:template name="insertPointer">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="cell-position"/>
		<xsl:param name="side"/>
		<xsl:param name="pointers"/>
		<xsl:param name="pointer"/>
		<xsl:param name="prev-pointers" select="''"/>
		
		<xsl:variable name="current-pointer" select="substring-before($pointers, ',')"/>
		<xsl:variable name="next-pointers" select="substring-after($pointers, ',')"/>
		
		<xsl:choose>
			<xsl:when test="$next-pointers=''">
				<xsl:choose>
					<xsl:when test="$current-pointer!=''">
						<xsl:variable name="comparison">
							<xsl:call-template name="comparePointer">
								<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
								<xsl:with-param name="cell-position" select="$cell-position"/>
								<xsl:with-param name="side" select="$side"/>
								<xsl:with-param name="p1" select="$pointer"/>
								<xsl:with-param name="p2" select="$current-pointer"/>
							</xsl:call-template>
						</xsl:variable>
						<xsl:choose>
							<xsl:when test="$comparison='left'">
								<xsl:value-of select="concat($prev-pointers, $pointer, ',', $current-pointer, ',')"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="concat($prev-pointers, $current-pointer, ',', $pointer, ',')"/>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="concat($prev-pointers, $pointer, ',')"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:otherwise>
				<xsl:variable name="comparison">
					<xsl:call-template name="comparePointer">
						<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
						<xsl:with-param name="cell-position" select="$cell-position"/>
						<xsl:with-param name="side" select="$side"/>
						<xsl:with-param name="p1" select="$pointer"/>
						<xsl:with-param name="p2" select="$current-pointer"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:choose>
					<!-- If the comparison means p1 is to the left of p2, insert p1 just before p2 and return the array of pointers for the region -->
					<xsl:when test="$comparison='left'">
						<xsl:value-of select="concat($prev-pointers, $pointer, ',', $current-pointer, ',', $next-pointers)"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:call-template name="insertPointer">
							<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
							<xsl:with-param name="cell-position" select="$cell-position"/>
							<xsl:with-param name="side" select="$side"/>
							<xsl:with-param name="prev-pointers" select="concat($prev-pointers, $current-pointer, ',')"/>
							<xsl:with-param name="pointers" select="$next-pointers"/>
							<xsl:with-param name="pointer" select="$pointer"/>
						</xsl:call-template>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template name="add_fromPointer">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="loaded-pointers"/>
		<xsl:param name="to-node"/>
		<xsl:param name="from-node"/>
		
		<xsl:variable name="from-node-content">
			<xsl:call-template name="getNodeByNumber">
				<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
				<xsl:with-param name="node-number" select="$from-node"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="from-cell-position">
			<xsl:call-template name="getPosition">
				<xsl:with-param name="node-content" select="$from-node-content"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:variable name="to-node-content">
			<xsl:call-template name="getNodeByNumber">
				<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
				<xsl:with-param name="node-number" select="$to-node"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="to-cell-position">
			<xsl:call-template name="getPosition">
				<xsl:with-param name="node-content" select="$to-node-content"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:variable name="pointer-region">
			<xsl:call-template name="getPointerRegion">
				<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
				<xsl:with-param name="cell-position" select="$to-cell-position"/>
				<xsl:with-param name="pointer-node-number" select="$from-node"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:variable name="region-content">
			<xsl:call-template name="getPointerRegionContent">
				<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
				<xsl:with-param name="node-number" select="$to-node"/>
				<xsl:with-param name="region" select="$pointer-region"/>
			</xsl:call-template>
		</xsl:variable>
		
		<!-- Modified pointer array after inserting the from-pointer -->
		<xsl:call-template name="setPointerRegionContent">
			<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
			<xsl:with-param name="node-number" select="$to-node"/>
			<xsl:with-param name="region" select="$pointer-region"/>
			<xsl:with-param name="new-content">
				<xsl:call-template name="insertPointer">
					<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
					<xsl:with-param name="cell-position" select="$to-cell-position"/>
					<xsl:with-param name="side">
						<xsl:choose>
							<xsl:when test="$pointer-region='left' or $pointer-region='right'">
								<xsl:value-of select="$pointer-region"/>
							</xsl:when>
							<xsl:when test="$pointer-region='bottom-left' or $pointer-region='bottom-mid' or $pointer-region='bottom-right'">bottom</xsl:when>
							<xsl:when test="$pointer-region='top-left' or $pointer-region='top-mid' or $pointer-region='top-right'">top</xsl:when>
						</xsl:choose>
					</xsl:with-param>
					<xsl:with-param name="pointers" select="$region-content"/>
					<xsl:with-param name="pointer" select="concat('f', $from-node)"/>
				</xsl:call-template>
			</xsl:with-param>
		</xsl:call-template>
	</xsl:template>
	
	
	<!--
		Returns [str], where "p1 is [str] (of) p2"; [str] is an element of {'left', 'right', 'above', 'under'}
	-->
	<xsl:template name="comparePointer">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="cell-position"/>
		<xsl:param name="side"/>
		<xsl:param name="p1"/>
		<xsl:param name="p2"/>
		
		<xsl:choose>
			<xsl:when test="substring($p1, 2)=substring($p2, 2)">left</xsl:when>
			<xsl:otherwise>
				<xsl:variable name="p1-node-content">
					<xsl:call-template name="getNodeByNumber">
						<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
						<xsl:with-param name="node-number" select="substring($p1, 2)"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="p1-cell-pos">
					<xsl:variable name="position">
						<xsl:call-template name="getPosition">
							<xsl:with-param name="node-content" select="$p1-node-content"/>
						</xsl:call-template>
					</xsl:variable>
					<xsl:value-of select="number($position)"/>
				</xsl:variable>
				<xsl:variable name="p2-node-content">
					<xsl:call-template name="getNodeByNumber">
						<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
						<xsl:with-param name="node-number" select="substring($p2, 2)"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="p2-cell-pos">
					<xsl:variable name="position">
						<xsl:call-template name="getPosition">
							<xsl:with-param name="node-content" select="$p2-node-content"/>
						</xsl:call-template>
					</xsl:variable>
					<xsl:value-of select="number($position)"/>
				</xsl:variable>
				
				<xsl:variable name="mod1" select="$p1-cell-pos mod 5"/>
				<xsl:variable name="mod2" select="$p2-cell-pos mod 5"/>
				
				<xsl:choose>
					<xsl:when test="$side='left' or $side='right'">
						<xsl:choose>
							<xsl:when test="$p1-cell-pos &gt; $p2-cell-pos">above</xsl:when><!-- was: 'above' -->
							<xsl:otherwise>under</xsl:otherwise><!-- was: 'under' -->
						</xsl:choose>
					</xsl:when>
					<xsl:when test="$side='bottom'">
						<xsl:choose>
							<!-- These two are for unique-edit-steps -->
							<xsl:when test="$p1-cell-pos = $cell-position + 1">right</xsl:when>
							<xsl:when test="$p2-cell-pos = $cell-position + 1">left</xsl:when>
							
							<xsl:when test="$mod1 &lt; $mod2">right</xsl:when><!-- left -->
							<xsl:when test="$mod1 &gt; $mod2">left</xsl:when><!-- right -->
							<xsl:otherwise>
								<xsl:choose>
									<xsl:when test="$mod1 = 1">
										<xsl:choose>
											<xsl:when test="$p1-cell-pos &gt; $p2-cell-pos">right</xsl:when>
											<xsl:otherwise>left</xsl:otherwise>
										</xsl:choose>
									</xsl:when>
									<xsl:when test="$mod1 = 3 or $mod1 = 5">
										<xsl:choose>
											<xsl:when test="$p1-cell-pos &lt; $p2-cell-pos">right</xsl:when>
											<xsl:otherwise>left</xsl:otherwise>
										</xsl:choose>
									</xsl:when>
								</xsl:choose>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:when>
					<xsl:when test="$side='top'">
						<xsl:choose>
							<xsl:when test="$mod1 &lt; $mod2">right</xsl:when><!-- left -->
							<xsl:when test="$mod1 &gt; $mod2">left</xsl:when><!-- right -->
							<xsl:otherwise>
								<xsl:choose>
									<xsl:when test="$mod1 = 1">
										<xsl:choose>
											<xsl:when test="$p1-cell-pos &gt; $p2-cell-pos">left</xsl:when>
											<xsl:otherwise>right</xsl:otherwise>
										</xsl:choose>
									</xsl:when>
									<xsl:when test="$mod1 = 3 or $mod1 = 5">
										<xsl:choose>
											<xsl:when test="$p1-cell-pos &lt; $p2-cell-pos">left</xsl:when>
											<xsl:otherwise>right</xsl:otherwise>
										</xsl:choose>
									</xsl:when>
								</xsl:choose>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:when>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template name="getPointerRegionContent">
		<xsl:param name="loaded-pointers"/>
		<xsl:param name="node-number"/>
		<xsl:param name="region"/>
		
		<xsl:variable name="pointer-content">
			<xsl:call-template name="getNodeByNumber">
				<xsl:with-param name="loaded-steps" select="$loaded-pointers"/>
				<xsl:with-param name="node-number" select="$node-number"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:choose>
			<xsl:when test="$region='top-left'">
				<xsl:value-of select="substring-before(substring-after($pointer-content, '['), '|')"/>
			</xsl:when>
			<xsl:when test="$region='top-mid'">
				<xsl:value-of select="substring-before(substring-after($pointer-content, '|'), '|')"/>
			</xsl:when>
			<xsl:when test="$region='top-right'">
				<xsl:value-of select="substring-before(substring-after(substring-after($pointer-content, '|'), '|'), ']')"/>
			</xsl:when>
			<xsl:when test="$region='right'">
				<xsl:value-of select="substring-before(substring-after(substring-after($pointer-content, '['), '['), ']')"/>
			</xsl:when>
			<xsl:when test="$region='bottom-left'">
				<xsl:variable name="bottom-content" select="substring-before(substring-after(substring-after(substring-after($pointer-content, '['), '['), '['), ']')"/>
				<xsl:value-of select="substring-before($bottom-content, '|')"/>
			</xsl:when>
			<xsl:when test="$region='bottom-mid'">
				<xsl:variable name="bottom-content" select="substring-before(substring-after(substring-after(substring-after($pointer-content, '['), '['), '['), ']')"/>
				<xsl:value-of select="substring-before(substring-after($bottom-content, '|'), '|')"/>
			</xsl:when>
			<xsl:when test="$region='bottom-right'">
				<xsl:variable name="bottom-content" select="substring-before(substring-after(substring-after(substring-after($pointer-content, '['), '['), '['), ']')"/>
				<xsl:value-of select="substring-after(substring-after($bottom-content, '|'), '|')"/>
			</xsl:when>
			<xsl:when test="$region='left'">
				<xsl:value-of select="substring-before(substring-after(substring-after(substring-after(substring-after($pointer-content, '['), '['), '['), '['), ']')"/>
			</xsl:when>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template name="getPointerRegion">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="cell-position"/>
		<xsl:param name="pointer-node-number"/>
		
		<xsl:variable name="pointer-cell-position">
			<xsl:variable name="pointer-node-content">
				<xsl:call-template name="getNodeByNumber">
					<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
					<xsl:with-param name="node-number" select="$pointer-node-number"/>
				</xsl:call-template>
			</xsl:variable>
			<xsl:call-template name="getPosition">
				<xsl:with-param name="node-content" select="$pointer-node-content"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:variable name="pos1" select="number($cell-position)"/>
		<xsl:variable name="pos2" select="number($pointer-cell-position)"/>
		
		<xsl:choose>
			<xsl:when test="$pos1 mod 5 = 1">
				<xsl:choose>
					<!-- pos2 is a unique-edit-step of pos1 -->
					<xsl:when test="$pos2 = $pos1 + 1">bottom-right</xsl:when>
					<!-- pos2 is to the right of pos1 -->
					<xsl:when test="$pos2 = $pos1 + 2">right</xsl:when>
					<!-- pos2 is to the far right of pos1 -->
					<xsl:when test="$pos2 = $pos1 + 4">
						<xsl:variable name="notBlocked">
							<xsl:call-template name="isAvailablePosition">
								<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
								<xsl:with-param name="cell-position" select="$pos1 + 2"/>
							</xsl:call-template>
						</xsl:variable>
						<xsl:choose>
							<xsl:when test="$notBlocked='true'">right</xsl:when>
							<xsl:otherwise>top-right</xsl:otherwise>
						</xsl:choose>
					</xsl:when>
					<!-- pos2 is directly underneath pos1 -->
					<xsl:when test="$pos2 = $pos1 + 5">bottom-mid</xsl:when>
					<!-- pos2 is directly above pos1 -->
					<xsl:when test="$pos2 = $pos1 - 5">top-mid</xsl:when>
					<!-- pos2 is underneath pos1 but not directly -->
					<xsl:when test="$pos2 &gt; $pos1 and $pos2 mod 5 = $pos1 mod 5">bottom-left</xsl:when>
					<!-- pos2 is above pos1 but not directly -->
					<xsl:when test="$pos2 &lt; $pos1 and $pos2 mod 5 = $pos1 mod 5">top-left</xsl:when>
					<!-- otherwise -->
					<xsl:when test="$pos2 &gt; $pos1 + 5">bottom-right</xsl:when>
					<xsl:when test="$pos2 &lt; $pos1">top-right</xsl:when>
				</xsl:choose>
			</xsl:when>
			<xsl:when test="$pos1 mod 5 = 2">top-left</xsl:when>
			<xsl:when test="$pos1 mod 5 = 3">
				<xsl:choose>
					<!-- pos2 is a unique-edit-step of pos1 -->
					<xsl:when test="$pos2 = $pos1 + 1">bottom-right</xsl:when>
					<!-- pos2 is to the left of pos1 -->
					<xsl:when test="$pos2 = $pos1 - 2">left</xsl:when>
					<!-- pos2 is to the right of pos1 -->
					<xsl:when test="$pos2 = $pos1 + 2">right</xsl:when>
					<!-- pos2 is directly underneath pos1 -->
					<xsl:when test="$pos2 = $pos1 + 5">bottom-mid</xsl:when>
					<!-- pos2 is directly above pos1 -->
					<xsl:when test="$pos2 = $pos1 - 5">top-mid</xsl:when>
					<!-- pos2 is underneath pos1 but not directly -->
					<xsl:when test="$pos2 &gt; $pos1 and $pos2 mod 5 = $pos1 mod 5">bottom-left</xsl:when>
					<!-- pos2 is above pos1 but not directly -->
					<xsl:when test="$pos2 &lt; $pos1 and $pos2 mod 5 = $pos1 mod 5">top-left</xsl:when>
					<!-- otherwise -->
					<xsl:when test="$pos2 &gt; $pos1 and $pos2 mod 5 = 0">bottom-right</xsl:when>
					<xsl:when test="$pos2 &gt; $pos1 and $pos2 mod 5 = 1">bottom-left</xsl:when>
					<xsl:when test="$pos2 &lt; $pos1 and $pos2 mod 5 = 0">top-right</xsl:when>
					<xsl:when test="$pos2 &lt; $pos1 and $pos2 mod 5 = 1">top-left</xsl:when>
				</xsl:choose>
			</xsl:when>
			<xsl:when test="$pos1 mod 5 = 4">top-left</xsl:when>
			<xsl:when test="$pos1 mod 5 = 0">
				<xsl:choose>
					<!-- pos2 is to the left of pos1 -->
					<xsl:when test="$pos2 = $pos1 - 2">left</xsl:when>
					<!-- pos2 is to the far left of pos1 -->
					<xsl:when test="$pos2 = $pos1 - 4">
						<xsl:variable name="notBlocked">
							<xsl:call-template name="isAvailablePosition">
								<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
								<xsl:with-param name="cell-position" select="$pos1 - 2"/>
							</xsl:call-template>
						</xsl:variable>
						<xsl:choose>
							<xsl:when test="$notBlocked='true'">left</xsl:when>
							<xsl:otherwise>top-left</xsl:otherwise>
						</xsl:choose>
					</xsl:when>
					<!-- pos2 is directly underneath pos1 -->
					<xsl:when test="$pos2 = $pos1 + 5">bottom-mid</xsl:when>
					<!-- pos2 is directly above pos1 -->
					<xsl:when test="$pos2 = $pos1 - 5">top-mid</xsl:when>
					<!-- pos2 is underneath pos1 but not directly -->
					<xsl:when test="$pos2 &gt; $pos1 and $pos2 mod 5 = $pos1 mod 5">bottom-left</xsl:when>
					<!-- pos2 is above pos1 but not directly -->
					<xsl:when test="$pos2 &lt; $pos1 and $pos2 mod 5 = $pos1 mod 5">top-left</xsl:when>
					<!-- otherwise -->
					<xsl:when test="$pos2 &gt; $pos1">bottom-left</xsl:when><!-- $pos2 &gt; $pos1 + 5 -->
					<xsl:when test="$pos2 &lt; $pos1">top-left</xsl:when><!-- "$pos2 &lt; $pos1 - 5" -->
				</xsl:choose>
			</xsl:when>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template name="key_exists">
		<xsl:param name="pseudo-array"/>
		<xsl:param name="key"/>
		
		<xsl:choose>
			<xsl:when test="substring-after($pseudo-array, concat('(', $key, '){'))!=''">true</xsl:when>
			<xsl:otherwise>false</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template name="getPointerNodeByNumber">
		<xsl:param name="loaded-pointers"/>
		<xsl:param name="node-number"/>
		
		<xsl:value-of select="substring-before(substring-after($loaded-pointers, concat('(', $node-number, '){')), '}')"/>
	</xsl:template>
	
	<!--
		Returns modified 'loaded-pointers' pseudo-array, where the node-number's node-side's content is replaced with 'new-pointers'
	-->
	<xsl:template name="replacePointers">
		<xsl:param name="loaded-pointers"/>
		<xsl:param name="node-number"/>
		<xsl:param name="node-side"/>
		<xsl:param name="new-pointers"/>
		
		<xsl:variable name="node-content">
			<xsl:call-template name="getNodeByNumber">
				<xsl:with-param name="loaded-steps" select="$loaded-pointers"/>
				<xsl:with-param name="node-number" select="$node-number"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="new-node-content">
			<xsl:choose>
				<xsl:when test="$node-side='top'">
					<xsl:value-of select="concat('[', $new-pointers, ']', substring-after($node-content, ']'))"/>
				</xsl:when>
				<xsl:when test="$node-side='right'">
					
				</xsl:when>
				<xsl:when test="$node-side='bottom'">
					
				</xsl:when>
				<xsl:when test="$node-side='left'">
					
				</xsl:when>
			</xsl:choose>
		</xsl:variable>
		
		<xsl:call-template name="assignNodeContent">
			<xsl:with-param name="pseudo-array" select="$loaded-pointers"/>
			<xsl:with-param name="index" select="$node-number"/>
			<xsl:with-param name="new-content" select="$node-content"/>
		</xsl:call-template>
	</xsl:template>
	
	<!--
		If 'index' does not exist in 'pseudo-array', then a new node is created with 'index' and assigned 'new-content'
	-->
	<xsl:template name="assignNodeContent">
		<xsl:param name="pseudo-array"/>
		<xsl:param name="index"/>
		<xsl:param name="new-content"/>
		
		<xsl:variable name="index-exists">
			<xsl:call-template name="key_exists">
				<xsl:with-param name="pseudo-array" select="$pseudo-array"/>
				<xsl:with-param name="key" select="$index"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="$index-exists='true'">
				<xsl:variable name="array-before">
					<xsl:value-of select="substring-before($pseudo-array, concat('(', $index, '){'))"/>
				</xsl:variable>
				<xsl:variable name="array-after">
					<xsl:value-of select="substring-after(substring-after($pseudo-array, concat('(', $index, '){')), '}')"/>
				</xsl:variable>
				
				<xsl:value-of select="concat($array-before, '(', $index, '){', $new-content, '}', $array-after)"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="concat($pseudo-array, '(', $index, '){', $new-content, '}')"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template name="printLoadedSteps">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="loaded-pointers"/>
		<xsl:param name="node-number" select="number(0)"/>
		<xsl:param name="nodes-total" select="number(0)"/>
		
		<xsl:comment>
			NEW LOADDED_POINTERS: <xsl:value-of select="$loaded-pointers"/>
		</xsl:comment>
		
		<xsl:choose>
			<xsl:when test="number($node-number)=0">
				<xsl:call-template name="printLoadedSteps">
					<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
					<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
					<xsl:with-param name="node-number" select="number(1)"/>
					<xsl:with-param name="nodes-total">
						<xsl:call-template name="getHighestNodeNumber">
							<xsl:with-param name="node-list" select="$loaded-steps"/>
						</xsl:call-template>
					</xsl:with-param>
				</xsl:call-template>
			</xsl:when>
			<xsl:when test="number($node-number) &gt; number($nodes-total)">
				<!-- Stop printing the loaded-steps -->
			</xsl:when>
			<xsl:otherwise>
				<xsl:variable name="node-content">
					<xsl:call-template name="getNodeByNumber">
						<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
						<xsl:with-param name="node-number" select="$node-number"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="step-id">
					<xsl:call-template name="getStepId">
						<xsl:with-param name="node-content" select="$node-content"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="cell-position">
					<xsl:call-template name="getPosition">
						<xsl:with-param name="node-content" select="$node-content"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="node-pointers">
					<xsl:call-template name="getNodePointers">
						<xsl:with-param name="node-content" select="$node-content"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="step-label">
					<xsl:for-each select="/system-workflow-definition">
						<xsl:for-each select="steps/step[@identifier=$step-id] | non-ordered-steps/step[@identifier=$step-id]">
							<xsl:value-of select="@label"/>
						</xsl:for-each>
					</xsl:for-each>
				</xsl:variable>
				<xsl:variable name="is-last-step">
					<xsl:choose>
						<xsl:when test="$node-pointers=''">true</xsl:when>
						<xsl:otherwise>false</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				
				<xsl:call-template name="makePositionCell">
					<xsl:with-param name="position" select="number($cell-position)"/>
					<xsl:with-param name="step-id" select="$step-id"/>
					<xsl:with-param name="step-label" select="$step-label"/>
					<xsl:with-param name="node-number" select="$node-number"/>
					<xsl:with-param name="is-last-step" select="$is-last-step"/>
				</xsl:call-template>
				
				<xsl:call-template name="drawArrows">
					<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
					<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
					<xsl:with-param name="node-number" select="$node-number"/>
					<xsl:with-param name="node-pointers" select="$node-pointers"/>
				</xsl:call-template>
				
				<xsl:comment>LOADED-POINTERS***: <xsl:value-of select="$loaded-pointers"/></xsl:comment>
				<xsl:call-template name="printLoadedSteps">
					<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
					<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
					<xsl:with-param name="node-number" select="number($node-number)+1"/>
					<xsl:with-param name="nodes-total" select="number($nodes-total)"/>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template name="drawArrows">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="loaded-pointers"/>
		<!-- <xsl:param name="position"/> -->
		<xsl:param name="node-number"/>
		<xsl:param name="node-pointers"/>
		
		<xsl:comment>
			HERE LOADED_POINTERS: <xsl:value-of select="$loaded-pointers"/>
		</xsl:comment>
		
		<xsl:if test="$node-pointers!=''">
			<xsl:variable name="node-pointer" select="substring-before($node-pointers, ']')"/>
			<xsl:variable name="node-pointer-content">
				<xsl:call-template name="getNodeByNumber">
					<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
					<xsl:with-param name="node-number" select="$node-pointer"/>
				</xsl:call-template>
			</xsl:variable>
			<xsl:variable name="from-position">
				<xsl:call-template name="getPosition">
					<xsl:with-param name="node-content">
						<xsl:call-template name="getNodeByNumber">
							<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
							<xsl:with-param name="node-number" select="$node-number"/>
						</xsl:call-template>
					</xsl:with-param>
				</xsl:call-template>
			</xsl:variable>
			<xsl:variable name="to-position">
				<xsl:call-template name="getPosition">
					<xsl:with-param name="node-content" select="$node-pointer-content"/>
				</xsl:call-template>
			</xsl:variable>
			<!--
			<xsl:comment>
				LOADED-STEPS: <xsl:value-of select="$loaded-steps"/>
				NODE-POINTER: <xsl:value-of select="$node-pointer"/>
				NODE-POINTER-CONTENT: <xsl:value-of select="$node-pointer-content"/>
				FROM-POSITION: <xsl:value-of select="$from-position"/>
				TO-POSITION: <xsl:value-of select="$to-position"/>
			</xsl:comment>
			-->
			<xsl:variable name="arrow-coors">
				<xsl:call-template name="getArrowCoors">
					<xsl:with-param name="from-position" select="$from-position"/>
					<xsl:with-param name="to-position" select="$to-position"/>
				</xsl:call-template>
			</xsl:variable>
			<xsl:variable name="fromCoor" select="substring-before($arrow-coors, ';')"/>
			<xsl:variable name="fromCoorX" select="substring-before($fromCoor, ',')"/>
			<xsl:variable name="fromCoorY" select="substring-after($fromCoor, ',')"/>
			<xsl:variable name="toCoor" select="substring-after($arrow-coors, ';')"/>
			<xsl:variable name="toCoorX" select="substring-before($toCoor, ',')"/>
			<xsl:variable name="toCoorY" select="substring-after($toCoor, ',')"/>
			
			<xsl:call-template name="drawArrowPath">
				<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
				<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
				<xsl:with-param name="from-node" select="$node-number"/>
				<xsl:with-param name="to-node" select="$node-pointer"/>
			</xsl:call-template>
			
			<!-- Make recursive call back to same template to process the rest of the node-pointers also -->
			<xsl:call-template name="drawArrows">
				<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
				<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
				<xsl:with-param name="node-number" select="$node-number"/>
				<xsl:with-param name="node-pointers" select="substring-after($node-pointers, ']')"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	
	<!--
		Initializes the processing of the workflow's steps and returns the loaded-steps pseudo-array holding the information to all processed steps
	-->
	<xsl:template name="beginProcessingSteps">
		<xsl:param name="initial-step"/>
		
		<xsl:call-template name="processStep">
			<xsl:with-param name="loaded-steps" select="concat('(1){', $initial-step, ']', '1]}')"/>
			<xsl:with-param name="node-number" select="number(1)"/>
		</xsl:call-template>
	</xsl:template>
	
	<!-- 
		Processes and recurses each step while updating the 'loaded-steps' pseudo-array holding the information to each of the processed steps.
		The 'loaded-steps' pseudo-array is returned at the end.
	-->
	<xsl:template name="processStep">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="node-number"/>
		
		<xsl:variable name="nodeExists">
			<xsl:call-template name="nodeExists">
				<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
				<xsl:with-param name="node-number" select="$node-number"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:choose>
			<xsl:when test="$nodeExists='true'">
				<!--
					When the node exists, use the makeNodePointers template to create a modified/updated version 
					of loaded-steps as it adds all the steps the current step points to into the 'loaded-steps' pseudo-array
				-->
				<xsl:variable name="new-loaded-steps">
					<xsl:call-template name="makeNodePointers">
						<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
						<xsl:with-param name="node-number" select="$node-number"/>
					</xsl:call-template>
				</xsl:variable>
				
				<!-- Process the next node-number -->
				<xsl:call-template name="processStep">
					<xsl:with-param name="loaded-steps" select="$new-loaded-steps"/>
					<xsl:with-param name="node-number" select="number($node-number)+1"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<!-- Return the processed and loaded 'loaded-steps' pseudo-array -->
				<xsl:value-of select="$loaded-steps"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		Returns 'true' or 'false' depending on whether a node with 'node-number' exists in the 'loaded-steps' pseudo-array.
	-->
	<xsl:template name="nodeExists">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="node-number"/>
		
		<xsl:choose>
			<xsl:when test="substring-after($loaded-steps, concat('(', $node-number, '){'))=''">false</xsl:when>
			<xsl:otherwise>true</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		'Loaded-steps' should include the step that is about to be processed (its index and cell position), and 'node-number' 
		should be the number of the node (the index of the step in the pseudo-array 'loaded-steps').
	-->
	<xsl:template name="processStepOld">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="action"/>
		<xsl:param name="number-of-actions"/>
		<xsl:param name="node-number"/>
		
		<xsl:choose>
			<!--
				When the action index is greater than the total number of actions for the given step indexed by $node-number,
				recall this template with the next node-number to process it.
			-->
			<xsl:when test="$action &gt; $number-of-actions">
				<xsl:call-template name="processStep">
					<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
					<xsl:with-param name="action" select="number(0)"/>
					<xsl:with-param name="number-of-actions" select="number(0)"/>
					<xsl:with-param name="node-number" select="number($node-number)+1"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:variable name="node-content">
					<xsl:call-template name="getNodeByNumber">
						<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
						<xsl:with-param name="node-number" select="$node-number"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="step-id">
					<xsl:call-template name="getStepId">
						<xsl:with-param name="node-content" select="$node-content"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="cell-position">
					<xsl:call-template name="getPosition">
						<xsl:with-param name="node-content" select="$node-content"/>
					</xsl:call-template>
				</xsl:variable>
				<!--
					I don't remember this template - anyways, makeNodePointers should take care of this and return
					a modified loaded-steps pseudo-array.
				<xsl:variable name="node-pointers">
					<xsl:call-template name="getNodePointers">
						<xsl:with-param name="node-content" select="$node-content"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="numberOfActions">
					<xsl:call-template name="countNodePointers">
						<xsl:with-param name="node-pointers" select="$node-pointers"/>
					</xsl:call-template>
				</xsl:variable>
				-->
				
				<xsl:choose>
					<xsl:when test="number($action)=0">
						<!-- Make node pointers -->
						<xsl:call-template name="makeNodePointers">
							<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
							<xsl:with-param name="node-number" select="$node-number"/>
						</xsl:call-template>
					</xsl:when>
					<xsl:otherwise>
						<xsl:variable name="numberOfActions">
							<xsl:call-template name="getNumberOfActions">
								<xsl:with-param name="step-id" select="$step-id"/>
							</xsl:call-template>
						</xsl:variable>
						<xsl:call-template name="processStep">
							<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
							<xsl:with-param name="action" select="number($action)+1"/>
							<xsl:with-param name="number-of-actions" select="$numberOfActions"/>
							<xsl:with-param name="node-number" select="$node-number"/>
						</xsl:call-template>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		Returns the highest node number from the 'node-list' (ie: "(1){initialize]1]3]}(2){manager-review]3]4]5]6]7]}").
	-->
	<xsl:template name="getHighestNodeNumber">
		<xsl:param name="node-list"/>
		<xsl:param name="highest" select="number(0)"/>
		
		<xsl:choose>
			<!-- If there are no nodes to iterate through any longer... -->
			<xsl:when test="substring-before($node-list, '}')=''">
				<xsl:value-of select="$highest"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:variable name="new-highest">
					<xsl:variable name="node-number">
						<xsl:value-of select="number(substring-before(substring-after($node-list, '('), ')'))"/>
					</xsl:variable>
					<xsl:choose>
						<xsl:when test="number($node-number) &gt; number($highest)">
							<xsl:value-of select="$node-number"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$highest"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<xsl:call-template name="getHighestNodeNumber">
					<xsl:with-param name="node-list" select="substring-after($node-list, '}')"/>
					<xsl:with-param name="highest" select="$new-highest"/>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		Returns the total number of actions that the step with the given step-id has.
	-->
	<xsl:template name="getNumberOfActions">
		<xsl:param name="step-id"/>
		
		<xsl:variable name="ifOrderedStep">
			<xsl:value-of select="count(/system-workflow-definition/steps/step[@identifier=$step-id]/actions/action)"/>
		</xsl:variable>
		<xsl:value-of select="$ifOrderedStep + count(/system-workflow-definition/non-ordered-steps/step[@identifier=$step-id]/actions/action)"/>
	</xsl:template>
	
	<!--
		Returns the step-id of a node, given a node's content.
	-->
	<xsl:template name="getStepId">
		<xsl:param name="node-content"/>
		<xsl:value-of select="substring-before($node-content, ']')"/>
	</xsl:template>
	
	<!--
		Returns the cell-position of a node, given a node's content.
	-->
	<xsl:template name="getPosition">
		<xsl:param name="node-content"/>
		<xsl:value-of select="substring-before(substring-after($node-content, ']'), ']')"/>
	</xsl:template>
	
	<!--
		Returns a pseudo-array of node-numbers that the current node points to.
	-->
	<xsl:template name="getNodePointers">
		<xsl:param name="node-content"/>
		<xsl:value-of select="substring-after(substring-after($node-content, ']'), ']')"/>
	</xsl:template>
	
	<!--
		Returns the total number of node-pointers included in the pseudo-array parameter 'node-pointers'.
	-->
	<xsl:template name="countNodePointers">
		<xsl:param name="node-pointers"/>
		<xsl:param name="total" select="number(0)"/>
		<xsl:choose>
			<!-- When there is nothing left to iterate through -->
			<xsl:when test="substring-before($node-pointers, ']')=''">
				<xsl:value-of select="$total"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="getNodePointers">
					<xsl:with-param name="node-pointers" select="substring-after($node-pointers, ']')"/>
					<xsl:with-param name="total" select="number($total)+1"/>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>		
	</xsl:template>
	
	<!--
		Returns the node-content of a node stored in 'loaded-steps' with the given node-number or an empty string if not found.
	-->
	<xsl:template name="getNodeByNumber">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="node-number"/>
		<xsl:value-of select="substring-before(substring-after($loaded-steps, concat('(', $node-number, '){')), '}')"/>
	</xsl:template>
	
	<!--
		Returns the node-content of a node stored in 'loaded-steps' with the given step-id.
	-->
	<xsl:template name="getNodeById">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="step-id"/>
		
		<xsl:variable name="current-node" select="substring-before(substring-after($loaded-steps, '{'), '}')"/>
		<xsl:variable name="current-step-id">
			<xsl:call-template name="getStepId">
				<xsl:with-param name="node-content" select="$current-node"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:choose>
			<xsl:when test="$loaded-steps=''"></xsl:when>
			<xsl:when test="$step-id=$current-step-id"><xsl:value-of select="$current-node"/></xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="getNodeById">
					<xsl:with-param name="loaded-steps" select="substring-after($loaded-steps, '}')"/>
					<xsl:with-param name="step-id" select="$step-id"/>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		Returns an altered loaded-steps pseudo-array, where the node with node-number has its node-pointers assigned.
	-->
	<xsl:template name="makeNodePointers">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="node-number"/>
		<xsl:param name="action-position" select="number(0)"/>
		<xsl:param name="last-action-position" select="number(0)"/>
		<xsl:param name="node-list" select="''"/>
		
		<!-- 
			Retrieve the node-content so that the step-id and cell-position can be determined.
			Also, determine the step-id and cell-position for the current step by the node-number.
		-->
		<xsl:variable name="node-content">
			<xsl:call-template name="getNodeByNumber">
				<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
				<xsl:with-param name="node-number" select="$node-number"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="step-id">
			<xsl:call-template name="getStepId">
				<xsl:with-param name="node-content" select="$node-content"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="cell-position">
			<xsl:call-template name="getPosition">
				<xsl:with-param name="node-content" select="$node-content"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:choose>
			<!-- If the action-position is zero then initialize the template recursion and set the correct last-action-position parameter -->
			<xsl:when test="number($action-position)=0">
				<!-- Determine the total number of actions that this step has to determine the last-action-position -->
				<xsl:variable name="last">
					<xsl:for-each select="/system-workflow-definition">
						<xsl:value-of select="count(steps/step[@identifier=$step-id]/actions/action)+count(non-ordered-steps/step[@identifier=$step-id]/actions/action)"/>
					</xsl:for-each>
				</xsl:variable>
				<!-- Recall the template to begin iterating at this step's first action -->
				<xsl:call-template name="makeNodePointers">
					<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
					<xsl:with-param name="node-number" select="$node-number"/>
					<xsl:with-param name="action-position" select="number(1)"/>
					<xsl:with-param name="last-action-position" select="$last"/>
				</xsl:call-template>
			</xsl:when>
			<!-- If the action-position has reached past the last-action position -->
			<xsl:when test="number($action-position) &gt; number($last-action-position)">
				<!-- Echo the rendered/altered loaded-steps at the end of the recursion -->
				
				<!-- Strip out the current node info, and append it to the end with the node-list included -->
				<xsl:variable name="new-loaded-steps">
					<xsl:call-template name="stripOutNodeByNumber">
						<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
						<xsl:with-param name="node-number" select="$node-number"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:value-of select="concat($new-loaded-steps, '(', $node-number, '){', $step-id, ']', $cell-position, ']', $node-list, '}')"/>
			</xsl:when>
			<xsl:otherwise>
				<!-- Create node-list -->
				<xsl:variable name="highestNodeNumber">
					<xsl:call-template name="getHighestNodeNumber">
						<xsl:with-param name="node-list" select="$loaded-steps"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="nextNodeNumber" select="number($highestNodeNumber)+1"/>
				<xsl:for-each select="/system-workflow-definition">
					<!-- This for-each statement is expected to only be called once -->
					<xsl:for-each select="steps/step[@identifier=$step-id]/actions/action[position()=$action-position] | non-ordered-steps/step[@identifier=$step-id]/actions/action[position()=$action-position]">
						<xsl:variable name="action-step-id">
							<xsl:choose>
								<xsl:when test="@move='forward'">
									<xsl:call-template name="getNextOrderedStep">
										<xsl:with-param name="step-id" select="$step-id"/>
									</xsl:call-template>
								</xsl:when>
								<xsl:when test="@move='reverse'">
									<xsl:call-template name="getPreviousOrderedStep">
										<xsl:with-param name="step-id" select="$step-id"/>
									</xsl:call-template>
								</xsl:when>
								<xsl:when test="@next-id">
									<xsl:value-of select="@next-id"/>
								</xsl:when>
							</xsl:choose>
						</xsl:variable>
						
						<!-- Determine whether the current action being iterated (which is also a step) has been loaded -->
						<xsl:variable name="stepIdIsLoaded">
							<xsl:call-template name="stepIdIsLoaded">
								<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
								<xsl:with-param name="step-id" select="$action-step-id"/>
							</xsl:call-template>
						</xsl:variable>
						
						<!-- Determine the newly modified $loaded-steps parameter -->
						<xsl:variable name="new-loaded-steps">
							<xsl:choose>
								<xsl:when test="$stepIdIsLoaded='true'"><xsl:value-of select="$loaded-steps"/></xsl:when>
								<xsl:otherwise>
									<xsl:variable name="next-position">
										<xsl:call-template name="getNextPosition">
											<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
											<xsl:with-param name="hasUniqueEditStep">
												<xsl:call-template name="hasUniqueEditStep">
													<xsl:with-param name="step-id" select="$action-step-id"/>
												</xsl:call-template>
											</xsl:with-param>
											<xsl:with-param name="isUniqueEditStep">
												<xsl:call-template name="isUniqueEditStep">
													<xsl:with-param name="step-id" select="$action-step-id"/>
													<xsl:with-param name="from-step" select="$step-id"/>
												</xsl:call-template>
											</xsl:with-param>
											<xsl:with-param name="cell-position" select="$cell-position"/>
											<xsl:with-param name="potential-cells">
												<xsl:call-template name="getPotentialLinkCells">
													<xsl:with-param name="cell-position" select="$cell-position"/>
												</xsl:call-template>
											</xsl:with-param>
										</xsl:call-template>
									</xsl:variable>
									
									<!-- Next append $action-step-id and $next-position to the $loaded-steps for a newly modified $loaded-steps param -->
									<xsl:value-of select="concat($loaded-steps, '(', $nextNodeNumber, '){', $action-step-id, ']', $next-position, ']}')"/>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:variable>
						
						<!-- Append to the node-list the new node-pointer, this node-list should be added into the loaded-steps pseudo-array at the end -->
						<xsl:variable name="new-node-list"> <!-- select="concat($node-list, $nextNodeNumber, ']')"/> -->
							<xsl:choose>
								<xsl:when test="$stepIdIsLoaded='true'">
									<xsl:variable name="pointerNumber">
										<!-- The node with 'step-id' will be in the loaded-steps because it is already loaded -->
										<xsl:call-template name="getNodeNumberByStepId">
											<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
											<xsl:with-param name="step-id" select="$action-step-id"/>
										</xsl:call-template>
									</xsl:variable>
									<xsl:value-of select="concat($node-list, $pointerNumber, ']')"/>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="concat($node-list, $nextNodeNumber, ']')"/>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:variable>
						
						<!-- Make the recursive call to the template with an increased action-position index and modified loaded-steps param -->
						<xsl:call-template name="makeNodePointers">
							<xsl:with-param name="loaded-steps" select="$new-loaded-steps"/>
							<xsl:with-param name="node-number" select="$node-number"/>
							<xsl:with-param name="action-position" select="number($action-position)+1"/>
							<xsl:with-param name="last-action-position" select="$last-action-position"/>
							<xsl:with-param name="node-list" select="$new-node-list"/>
						</xsl:call-template>
					</xsl:for-each>
				</xsl:for-each>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		Returns a modified loaded-steps where the node with 'node-number' is stripped out. If the node with 'node-number' is not in the 
		loaded-steps, then it is likely that it will return an empty string.
	-->
	<xsl:template name="stripOutNodeByNumber">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="node-number"/>
		
		<xsl:variable name="str-before" select="substring-before($loaded-steps, concat('(', $node-number, '){'))"/>
		<xsl:variable name="str-after" select="substring-after(substring-after($loaded-steps, concat('(', $node-number, '){')), '}')"/>
		<xsl:value-of select="concat($str-before, $str-after)"/>
	</xsl:template>
	
	<!--
		If the step with the provided step-id has any steps that it points to that are "unique-edit-steps" then this template
		call will return 'true', otherwise 'false'.
	-->
	<xsl:template name="hasUniqueEditStep">
		<xsl:param name="step-id"/>
		
		<xsl:variable name="temp">
			<xsl:for-each select="/system-workflow-definition">
				<!-- This for-each statement is expected to only be called once -->
				<xsl:for-each select="steps/step[@identifier=$step-id]/actions/action | non-ordered-steps/step[@identifier=$step-id]/actions/action">
					<xsl:variable name="action-step-id">
						<xsl:choose>
							<xsl:when test="@move='forward'">
								<xsl:call-template name="getNextOrderedStep">
									<xsl:with-param name="step-id" select="$step-id"/>
								</xsl:call-template>
							</xsl:when>
							<xsl:when test="@move='reverse'">
								<xsl:call-template name="getPreviousOrderedStep">
									<xsl:with-param name="step-id" select="$step-id"/>
								</xsl:call-template>
							</xsl:when>
							<xsl:when test="@next-id">
								<xsl:value-of select="@next-id"/>
							</xsl:when>
						</xsl:choose>
					</xsl:variable>
					
					<xsl:call-template name="isUniqueEditStep">
						<xsl:with-param name="step-id" select="$action-step-id"/>
						<xsl:with-param name="from-step" select="$step-id"/>
					</xsl:call-template>
					<!--
						Append some random character to the end of result so that substring-after($temp, 'true')
						will return either an empty string or something else.
					-->
					<xsl:text>]</xsl:text>
				</xsl:for-each>
			</xsl:for-each>
		</xsl:variable>
		
		<xsl:choose>
			<!--
				If 'true' shows up in the $temp varaible, then there is at least one instance of a unique-edit-step
				for the step with the provided step-id: return 'true'
			-->
			<xsl:when test="substring-after($temp, 'true')!=''">true</xsl:when>
			<!-- Otherwise, return 'false' -->
			<xsl:otherwise>false</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		Returns a cell-position number given loaded-steps, the step's current cell-position, the potential cells available,
		and whether the node in question: has a unique-edit-step, is a unique-edit-step.
	-->
	<xsl:template name="getNextPosition">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="hasUniqueEditStep"/>
		<xsl:param name="isUniqueEditStep"/>
		<xsl:param name="cell-position"/>
		<xsl:param name="potential-cells"/>
		
		<xsl:if test="$potential-cells!=''">
			<xsl:variable name="current-position" select="substring-before($potential-cells, ']')"/>
			
			<xsl:choose>
				<xsl:when test="$isUniqueEditStep='true'">
					<!--
						If isUniqueStep='true' then it is provided that $cell-position mod 5 != 0, and that $cell-position + 1 is the 
						cell-position to the lower-right.
					-->
					<xsl:variable name="isAvailable">
						<xsl:call-template name="isAvailablePosition">
							<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
							<xsl:with-param name="cell-position" select="number($cell-position)+1"/>
						</xsl:call-template>
					</xsl:variable>
					<xsl:choose>
						<!--
							If the lower-right cell position is available, return it; otherwise, act as though the current step is not
							a unique step
						-->
						<xsl:when test="$isAvailable='true'"><xsl:value-of select="number($cell-position)+1"/></xsl:when>
						<xsl:otherwise>
							<xsl:call-template name="getNextPosition">
								<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
								<xsl:with-param name="hasUniqueEditStep" select="$hasUniqueEditStep"/>
								<xsl:with-param name="isUniqueEditStep">false</xsl:with-param>
								<xsl:with-param name="cell-position" select="$cell-position"/>
								<xsl:with-param name="potential-cells" select="$potential-cells"/>
							</xsl:call-template>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:when>
				<xsl:otherwise>
					<xsl:variable name="isAvailable">
						<xsl:call-template name="isAvailablePosition">
							<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
							<xsl:with-param name="cell-position" select="$current-position"/>
						</xsl:call-template>
					</xsl:variable>
					<xsl:choose>
						<xsl:when test="$isAvailable='true'">
							<xsl:choose>
								<xsl:when test="(number($current-position) mod 5)=0">
									<xsl:choose>
										<xsl:when test="$hasUniqueEditStep='true'">
											<!--
												If the current step has a unique edit step, then it should not use a cell-position
												that lines the right-edge (which is identified by when the cell-position mod 5 = 0).
											-->
											<xsl:call-template name="getNextPosition">
												<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
												<xsl:with-param name="hasUniqueEditStep" select="$hasUniqueEditStep"/>
												<xsl:with-param name="isUniqueEditStep" select="$isUniqueEditStep"/>
												<xsl:with-param name="cell-position" select="$cell-position"/>
												<xsl:with-param name="potential-cells" select="substring-after($potential-cells, ']')"/>
											</xsl:call-template>
										</xsl:when>
										<xsl:otherwise><xsl:value-of select="$current-position"/></xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:otherwise><xsl:value-of select="$current-position"/></xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:otherwise>
							<!-- Keep searching for available space -->
							<xsl:call-template name="getNextPosition">
								<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
								<xsl:with-param name="hasUniqueEditStep" select="$hasUniqueEditStep"/>
								<xsl:with-param name="isUniqueEditStep" select="$isUniqueEditStep"/>
								<xsl:with-param name="cell-position" select="$cell-position"/>
								<xsl:with-param name="potential-cells" select="substring-after($potential-cells, ']')"/>
							</xsl:call-template>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:if>
	</xsl:template>
	
	<!--
		Returns 'true' or 'false' depending on whether the cell-position provided is available given the list of steps that have 
		already been loaded, which this template uses to check whether the cell-position is available still or if a previously loaded
		step has already claimed that position.
	-->
	<xsl:template name="isAvailablePosition">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="cell-position"/>
		<xsl:param name="node-number" select="number(1)"/>
		
		<xsl:variable name="node-content">
			<xsl:call-template name="getNodeByNumber">
				<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
				<xsl:with-param name="node-number" select="$node-number"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:choose>
			<!--
				If the step with node-number was not found, return 'true' because all nodes have been checked
				and none of them have the provided $cell-position.
			-->
			<xsl:when test="$node-content=''">true</xsl:when>
			<xsl:otherwise>
				<xsl:variable name="position">
					<xsl:call-template name="getPosition">
						<xsl:with-param name="node-content" select="$node-content"/>
					</xsl:call-template>
				</xsl:variable>
				
				<xsl:choose>
					<!-- If a previously loaded step already has the position in question, return false -->
					<xsl:when test="$position=$cell-position">false</xsl:when>
					<!-- Otherwise, check the other previously loaded steps to see if they have claimed the position in question already -->
					<xsl:otherwise>
						<xsl:call-template name="isAvailablePosition">
							<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
							<xsl:with-param name="cell-position" select="$cell-position"/>
							<xsl:with-param name="node-number" select="number($node-number)+1"/>
						</xsl:call-template>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template name="stepIdIsLoaded">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="step-id"/>
		<xsl:param name="node-number" select="number(0)"/>
		<xsl:param name="nodes-total" select="number(0)"/>
		
		<xsl:choose>
			<xsl:when test="number($node-number)=0">
				<xsl:variable name="totalNumberOfNodes">
					<xsl:call-template name="getHighestNodeNumber">
						<xsl:with-param name="node-list" select="$loaded-steps"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:call-template name="stepIdIsLoaded">
					<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
					<xsl:with-param name="step-id" select="$step-id"/>
					<xsl:with-param name="node-number" select="number(1)"/>
					<xsl:with-param name="nodes-total" select="$totalNumberOfNodes"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:when test="number($node-number) &gt; number($nodes-total)">false</xsl:when>
			<xsl:otherwise>
				<xsl:variable name="current-node-content">
					<xsl:call-template name="getNodeByNumber">
						<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
						<xsl:with-param name="node-number" select="number($node-number)"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="current-step-id">
					<xsl:call-template name="getStepId">
						<xsl:with-param name="node-content" select="$current-node-content"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:choose>
					<xsl:when test="$step-id=$current-step-id">true</xsl:when>
					<xsl:otherwise>
						<xsl:call-template name="stepIdIsLoaded">
							<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
							<xsl:with-param name="step-id" select="$step-id"/>
							<xsl:with-param name="node-number" select="number($node-number)+1"/>
							<xsl:with-param name="nodes-total" select="number($nodes-total)"/>
						</xsl:call-template>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		Returns the node-number of the node in 'loaded-steps' with the provided 'step-id', 
		or returns 'false' if the node cannot be found. 
	-->
	<xsl:template name="getNodeNumberByStepId">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="step-id"/>
		<xsl:param name="node-number" select="number(0)"/>
		<xsl:param name="nodes-total" select="number(0)"/>
		
		<xsl:choose>
			<xsl:when test="$node-number=0">
				<xsl:variable name="totalNumberOfNodes">
					<xsl:call-template name="getHighestNodeNumber">
						<xsl:with-param name="node-list" select="$loaded-steps"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:call-template name="getNodeNumberByStepId">
					<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
					<xsl:with-param name="step-id" select="$step-id"/>
					<xsl:with-param name="node-number" select="number(1)"/>
					<xsl:with-param name="nodes-total" select="$totalNumberOfNodes"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:when test="number($node-number) &gt; number($nodes-total)">false</xsl:when>
			<xsl:otherwise>
				<xsl:variable name="current-node-content">
					<xsl:call-template name="getNodeByNumber">
						<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
						<xsl:with-param name="node-number" select="number($node-number)"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="current-step-id">
					<xsl:call-template name="getStepId">
						<xsl:with-param name="node-content" select="$current-node-content"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:choose>
					<xsl:when test="$step-id=$current-step-id"><xsl:value-of select="$node-number"/></xsl:when>
					<xsl:otherwise>
						<xsl:call-template name="getNodeNumberByStepId">
							<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
							<xsl:with-param name="step-id" select="$step-id"/>
							<xsl:with-param name="node-number" select="number($node-number)+1"/>
							<xsl:with-param name="nodes-total" select="number($nodes-total)"/>
						</xsl:call-template>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		Finds the step indexed with 'node-number' and returns its cell-position, or it returns an empty string ('') if not found.
	-->
	<xsl:template name="getCellPositionFromLoadedSteps">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="node-number"/>
		
		<xsl:choose>
			<xsl:when test="substring-before($loaded-steps, ']')=''"></xsl:when>
			<xsl:otherwise>
				<xsl:choose>
					<xsl:when test="substring-after(substring-before($loaded-steps, ')'), '(')=$node-number">
						<xsl:value-of select="substring-after(substring-before($loaded-steps, ']'), '[')"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:call-template name="getCellPositionFromLoadedSteps">
							<xsl:with-param name="loaded-steps" select="substring-after($loaded-steps, ']')"/>
							<xsl:with-param name="node-number" select="$node-number"/>
						</xsl:call-template>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		This template is supposed to take in a parameter named "step-name", then store its position in a pseudo-array. Then
		this template should contain logic to determine the position of the steps it links to, checking whether those steps
		already have positions by checking from that pseudo-array.
		
		The parameter 'loaded-steps' serves as the pseudo-array, which is passed each time the template is called so that the
		array can change during the process of printing out each step.
	-->
	<xsl:template name="printStep">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="step-id"/>
		<xsl:param name="from-step"/>
		<xsl:param name="action"/>
		
		<xsl:variable name="cell-position">
			<xsl:call-template name="getCellPosition">
				<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
				<xsl:with-param name="from-step" select="$from-step"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="node-number">
			<xsl:call-template name="getNextNodeNumber">
				<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
				<xsl:with-param name="highest-step" select="number(0)"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="potential-link-cells">
			<xsl:call-template name="getPotentialLinkCells">
				<xsl:with-param name="cell-position" select="$cell-position"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:variable name="new-loaded-steps">
			<xsl:choose>
				<xsl:when test="number($action)=0">
					<xsl:value-of select="$loaded-steps"/>(<xsl:value-of select="$node-number"/><xsl:text>)</xsl:text>
					<xsl:value-of select="$step-id"/>[<xsl:value-of select="$cell-position"/><xsl:text>]</xsl:text>
				</xsl:when>
			</xsl:choose>
		</xsl:variable>
		
		
	</xsl:template>
	
	<xsl:template name="getCellPosition">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="from-step"/>
		
		<xsl:choose>
			<xsl:when test="$from-step=''">
				<xsl:value-of select="number(1)"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:variable name="from-position">
					<xsl:call-template name="getCellPositionById">
						<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
						<xsl:with-param name="step-id" select="$from-step"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="potential-links">
					<xsl:call-template name="getPotentialLinkCells">
						<xsl:with-param name="cell-position" select="$from-position"/>
					</xsl:call-template>
				</xsl:variable>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		Returns a step's stored cell position from the pseudo-array 'loaded-steps' or an empty string '' if 
		the step id is not stored in 'loaded-steps'.
	-->
	<xsl:template name="getCellPositionById">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="step-id"/>
		
		<xsl:choose>
			<xsl:when test="substring-before($loaded-steps, ']')=''"></xsl:when>
			<xsl:otherwise>
				<xsl:variable name="current-step" select="concat(substring-before($loaded-steps, ']'), ']')"/>
				<xsl:choose>
					<xsl:when test="substring-after(substring-before($current-step, '['), ')')=$step-id">
						<xsl:value-of select="substring-after(substring-before($current-step, ']'), '[')"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:call-template name="getCellPositionById">
							<xsl:with-param name="loaded-steps" select="substring-after($loaded-steps, ']')"/>
							<xsl:with-param name="step-id" select="$step-id"/>
						</xsl:call-template>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		This returns a pseudo-array of cell-positions that the passed cell-position may place nodes if they need to be created.
		Example pseudo-array: "3]8]10]15]13]"
	-->
	<xsl:template name="getPotentialLinkCells">
		<xsl:param name="cell-position"/>
		
		<xsl:choose>
			<xsl:when test="(number($cell-position) mod 5)=1">
				<xsl:value-of select="number($cell-position)+2"/><xsl:text>]</xsl:text>
				<xsl:value-of select="number($cell-position)+5"/><xsl:text>]</xsl:text>
				<xsl:value-of select="number($cell-position)+7"/><xsl:text>]</xsl:text>
				<xsl:value-of select="number($cell-position)+10"/><xsl:text>]</xsl:text>
				<xsl:value-of select="number($cell-position)+16"/><xsl:text>]</xsl:text>
			</xsl:when>
			<xsl:when test="(number($cell-position) mod 5)=3">
				<xsl:value-of select="number($cell-position)+2"/><xsl:text>]</xsl:text>
				<xsl:value-of select="number($cell-position)+5"/><xsl:text>]</xsl:text>
				<xsl:value-of select="number($cell-position)+3"/><xsl:text>]</xsl:text>
				<xsl:value-of select="number($cell-position)+7"/><xsl:text>]</xsl:text>
			</xsl:when>
			<xsl:when test="(number($cell-position) mod 5)=0">
				<xsl:value-of select="number($cell-position)-2"/><xsl:text>]</xsl:text>
				<xsl:value-of select="number($cell-position)+5"/><xsl:text>]</xsl:text>
				<xsl:value-of select="number($cell-position)+3"/><xsl:text>]</xsl:text>
				<xsl:value-of select="number($cell-position)+10"/><xsl:text>]</xsl:text>
				<xsl:value-of select="number($cell-position)+8"/><xsl:text>]</xsl:text>
			</xsl:when>
		</xsl:choose>
	</xsl:template>
	
	<!--
		This template determines from the 'loaded-steps' parameter, what the number of the next node should be. The
		'highest-step' parameter is recursively passed to keep track of the node with the highest number. Once all of the
		'loaded-steps' parameter has been traversed through, the next node number will be returned, which is the 
		'highest-step' + 1. If calling this template from another template, call with the highest-step parameter set
		to number(0).
	-->
	<xsl:template name="getNextNodeNumber">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="highest-step"/>
		
		<xsl:choose>
			<!-- When the loaded-steps pseudo-array has been completely traversed through -->
			<xsl:when test="substring-before($loaded-steps, ']')=''">
				<xsl:value-of select="number($highest-step) + number(1)"/>
			</xsl:when>
			<!-- When the loaded-steps pseudo-array still needs to be tranversed -->
			<xsl:otherwise>
				<xsl:variable name="current-step" select="substring-after(substring-before($loaded-steps, ')'), '(')"/>
				<xsl:variable name="new-highest-step">
					<xsl:choose>
						<xsl:when test="number($current-step) &gt; number($highest-step)">
							<xsl:value-of select="number($current-step)"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="number($highest-step)"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<!-- 
					Recurse through this template again with a modified loaded-steps pseudo-array and possibly a new 
					highest-step parameter (or its old one).
				-->
				<xsl:call-template name="getNextNodeNumber">
					<xsl:with-param name="loaded-steps" select="substring-after($loaded-steps, ']')"/>
					<xsl:with-param name="highest-step" select="number($new-highest-step)"/>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		Returns 'true' or 'false' depending on whether the step only calls back to the step
		it was called from and no other steps call the step.
	-->
	<xsl:template name="isUniqueEditStep">
		<xsl:param name="step-id"/>
		<xsl:param name="from-step"/>
		
		<!--
			This variable is no longer important
		<xsl:variable name="isOrderedStep">
			<xsl:call-template name="isOrderedStep">
				<xsl:with-param name="step-id" select="$step-id"/>
			</xsl:call-template>
		</xsl:variable>
		-->
		
		<xsl:variable name="onlyCallsBack">
			<xsl:call-template name="onlyCallsBack">
				<xsl:with-param name="step-id" select="$step-id"/>
				<xsl:with-param name="from-step" select="$from-step"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:variable name="numberOfOtherStepCalls">
			<xsl:call-template name="numberOfOtherStepCalls">
				<xsl:with-param name="step-id" select="$step-id"/>
				<xsl:with-param name="from-step" select="$from-step"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:choose>
			<xsl:when test="$onlyCallsBack='true' and $numberOfOtherStepCalls=0">true</xsl:when>
			<xsl:otherwise>false</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!-- 
		Returns 'true' if the step-id only calls back to the step with the step-id of the
		param 'from-step', otherwise, returns 'false'.
	-->
	<xsl:template name="onlyCallsBack">
		<xsl:param name="step-id"/>
		<xsl:param name="from-step"/>
		
		<xsl:choose>
			<!-- If the step is an ordered step -->
			<xsl:when test="count(/system-workflow-definition/steps/step[@identifier=$step-id])=1">
				<xsl:for-each select="/system-workflow-definition/steps/step[@identifier=$step-id]">
					<xsl:choose>
						<!-- When there is only one action -->
						<xsl:when test="count(actions/action)=1">
							<xsl:choose>
								<xsl:when test="count(actions/action[@next-id=$from-step])=1">
									<xsl:text>true</xsl:text>
								</xsl:when>
								<xsl:when test="count(actions/action[@move='forward'])=1">
									<xsl:variable name="nextOrderedStep">
										<xsl:call-template name="getNextOrderedStep">
											<xsl:with-param name="step-id" select="$step-id"/>
										</xsl:call-template>
									</xsl:variable>
									<xsl:choose>
										<xsl:when test="$nextOrderedStep=$from-step">true</xsl:when>
										<xsl:otherwise>false</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:when test="count(actions/action[@move='reverse'])=1">
									<xsl:variable name="previousOrderedStep">
										<xsl:call-template name="getPreviousOrderedStep">
											<xsl:with-param name="step-id" select="$step-id"/>
										</xsl:call-template>
									</xsl:variable>
									<xsl:choose>
										<xsl:when test="$previousOrderedStep=$from-step">true</xsl:when>
										<xsl:otherwise>false</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
							</xsl:choose>
						</xsl:when>
						<xsl:otherwise>false</xsl:otherwise>
					</xsl:choose>
				</xsl:for-each>
			</xsl:when>
			<!-- If the step is a non-ordered step -->
			<xsl:when test="count(/system-workflow-definition/non-ordered-steps/step[@identifier=$step-id])=1">
				<xsl:for-each select="/system-workflow-definition/non-ordered-steps/step[@identifier=$step-id]">
					<xsl:choose>
						<!-- When there is only one action -->
						<xsl:when test="count(actions/action)=1">
							<xsl:choose>
								<!-- When the action calls back to the 'from-step' -->
								<xsl:when test="count(actions/action[@next-id=$from-step])=1">
									<xsl:text>true</xsl:text>
								</xsl:when>
								<xsl:otherwise>false</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:otherwise>false</xsl:otherwise>
					</xsl:choose>
				</xsl:for-each>
			</xsl:when>
		</xsl:choose>
	</xsl:template>
	
	<!--
		Returns the identifier of the next ordered step or '' if the param 'step-id' is 
		not an identifier of an ordered step. Also returns an empty string ('') if the 'step-id'
		has no next ordered step.
	-->
	<xsl:template name="getNextOrderedStep">
		<xsl:param name="step-id"/>
		
		<xsl:variable name="step-position">
			<xsl:for-each select="/system-workflow-definition/steps/step">
				<xsl:if test="@identifier=$step-id">
					<xsl:value-of select="position()"/>
				</xsl:if>
			</xsl:for-each>
		</xsl:variable>
		<xsl:variable name="next-step-position" select="number($step-position)+1"/>
		<xsl:choose>
			<xsl:when test="$step-position=''"></xsl:when>
			<xsl:otherwise>
				<xsl:for-each select="/system-workflow-definition/steps/step[position()=$next-step-position]">
					<xsl:value-of select="@identifier"/>
				</xsl:for-each>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		Returns the identifier of the previous ordered step or '' if the param 'step-id' is 
		not an identifier of an ordered step. Also returns an empty string ('') if the 'step-id'
		has no previous ordered step.
	-->
	<xsl:template name="getPreviousOrderedStep">
		<xsl:param name="step-id"/>
		
		<xsl:variable name="step-position">
			<xsl:for-each select="/system-workflow-definition/steps/step">
				<xsl:if test="@identifier=$step-id">
					<xsl:value-of select="position()"/>
				</xsl:if>
			</xsl:for-each>
		</xsl:variable>
		<xsl:variable name="previous-step-position" select="number($step-position)-1"/>
		<xsl:choose>
			<xsl:when test="$step-position=''"></xsl:when>
			<xsl:otherwise>
				<xsl:for-each select="/system-workflow-definition/steps/step[position()=$previous-step-position]">
					<xsl:value-of select="@identifier"/>
				</xsl:for-each>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		Returns 'true' if the step-id is the step-id of an ordered step or 'false' otherwise.
	-->
	<xsl:template name="isOrderedStep">
		<xsl:param name="step-id"/>
		<xsl:choose>
			<xsl:when test="count(/system-workflow-definition/steps/step[@identifier=$step-id])&gt;=1">true</xsl:when>
			<xsl:otherwise>false</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		Returns the number of times the step with 'step-id' is called from steps other than the 
		step with the step-id of parameter 'from-step'.
	-->
	<xsl:template name="numberOfOtherStepCalls">
		<xsl:param name="step-id"/>
		<xsl:param name="from-step"/>
		
		<xsl:variable name="step-position">
			<xsl:for-each select="/system-workflow-definition/steps/step">
				<xsl:if test="@identifier=$step-id">
					<xsl:value-of select="position()"/>
				</xsl:if>
			</xsl:for-each>
		</xsl:variable>
		<xsl:variable name="otherCallsFromOrderedSteps">
			<xsl:value-of select="count(/system-workflow-definition/steps/step[@identifier!=$from-step]/actions/action[@next-id=$step-id]) +
									count(/system-workflow-definition/steps/step[position()=number($step-position)-1]/actions/action[@move='forward' and ../../@identifier!=$step-id])"/>
		</xsl:variable>
		<xsl:value-of select="$otherCallsFromOrderedSteps + count(/system-workflow-definition/non-ordered-steps/step/actions/action[@next-id=$step-id])"/>
	</xsl:template>
	
	<!--
		Returns the number of times the step with 'step-id' is called total.
		@param step-id is either an ordered-step or a non-ordered-step
	-->
	<xsl:template name="numberOfStepCalls">
		<xsl:param name="step-id"/>
		
		<xsl:variable name="callsFromOrderedSteps">
			<xsl:variable name="step-position">
				<xsl:for-each select="/system-workflow-definition/steps/step">
					<xsl:if test="@identifier=$step-id">
						<xsl:value-of select="position()"/>
					</xsl:if>
				</xsl:for-each>
			</xsl:variable>
			<xsl:variable name="isOrderedStep">
				<!-- Find out whether $step-id is an ordered step, template call returns 'true' or 'false' -->
				<xsl:call-template name="isOrderedStep">
					<xsl:with-param name="step-id" select="$step-id"/>
				</xsl:call-template>
			</xsl:variable>
			
			<xsl:choose>
				<xsl:when test="$isOrderedStep='true'">
					<!--
						If 'step-id' parameter is an ordered step, account for whether the step before it or after it calls to it
						using an action's 'move' attribute.
					-->
					<xsl:for-each select="/system-workflow-definition/steps">
						<xsl:value-of select="count(step/actions/action[@next-id=$step-id]) +
											count(step[position()=number($step-position)-1]/actions/action[@move='forward']) +
											count(step[position()=number($step-position)+1]/actions/action[@move='reverse'])"/>
					</xsl:for-each>
				</xsl:when>
				<xsl:otherwise>
					<!--
						If the 'step-id' step is not an ordered step, simply account for when ordered steps call to the step
						using a transition (the 'next-id' attribute of an action element).
					-->
					<xsl:for-each select="/system-workflow-definition/steps">
						<xsl:value-of select="count(step/actions/action[@next-id=$step-id])"/>
					</xsl:for-each>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="callsFromNonOrderedSteps">
			<xsl:for-each select="/system-workflow-definition/non-ordered-steps">
				<xsl:value-of select="count(step/actions/action[@next-id=$step-id])"/>
			</xsl:for-each>
		</xsl:variable>
		
		<xsl:value-of select="number($callsFromOrderedSteps) + number($callsFromNonOrderedSteps)"/>
	</xsl:template>
	
	<xsl:template name="getUserPositions">
		<xsl:param name="currentPosition"/>
		<xsl:param name="iterPosition"/>
		<xsl:param name="currentUserPositions"/>
		
		<xsl:choose>
			<xsl:when test="count(/system-workflow-definition/steps/step[@default-user][position()=$iterPosition])=0">
				<xsl:value-of select="$currentUserPositions"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:for-each select="/system-workflow-definition/steps/step[@default-user][position()=$iterPosition]">
					<xsl:variable name="prevInstance">
						<xsl:variable name="username" select="@default-user"/>
						<xsl:for-each select="../step[@default-user]">
							<xsl:if test="@default-user=$username and position() &lt; $iterPosition">
								<xsl:text>yes!</xsl:text>
							</xsl:if>
						</xsl:for-each>
					</xsl:variable>
					
					[instance]<xsl:value-of select="$prevInstance"/>[/instance]
					
					<xsl:choose>
						<xsl:when test="$prevInstance = ''">
							<xsl:call-template name="getUserPositions">
								<xsl:with-param name="iterPosition" select="$iterPosition+1"/>
								<xsl:with-param name="currentPosition" select="$currentPosition+1"/>
								<xsl:with-param name="currentUserPositions" select="concat($currentUserPositions, @default-user, '(', $currentPosition, ')')"/>
							</xsl:call-template>
						</xsl:when>
						<xsl:otherwise>
							<xsl:call-template name="getUserPositions">
								<xsl:with-param name="iterPosition" select="$iterPosition+1"/>
								<xsl:with-param name="currentPosition" select="$currentPosition"/>
								<xsl:with-param name="currentUserPositions" select="$currentUserPositions"/>
							</xsl:call-template>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:for-each>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
	
		Should be called like so:
		<xsl:call-template name="findUserByPosition">
			<xsl:with-param name="findPosition" select="2"/>
			<xsl:with-param name="currentPosition" select="1"/> /* currentPosition is always 1 */
			<xsl:with-param name="userString" select="$user_positions"/>
		</xsl:call-template>
	
	-->
	<xsl:template name="findUserByPosition">
		<xsl:param name="findPosition"/>
		<xsl:param name="currentPosition"/>
		<xsl:param name="userString"/>
		
		<xsl:choose>
			<xsl:when test="$currentPosition=$findPosition">
				<xsl:value-of select="substring-before($userString, '(')"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="findUserByPosition">
					<xsl:with-param name="findPosition" select="$findPosition"/>
					<xsl:with-param name="currentPosition" select="$currentPosition+1"/>
					<xsl:with-param name="userString" select="substring-after($userString, ')')"/>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
	
		<xsl:call-template name="getTotalNumberOfTokens">
			<xsl:with-param name="numberOfTokensCounted">0</xsl:with-param>
			<xsl:with-param name="token_string" select="$user_positions"/>
		</xsl:call-template>
	
	-->
	<xsl:template name="getTotalNumberOfTokens">
		<xsl:param name="numberOfTokensCounted"/>
		<xsl:param name="token_string"/>
		
		<xsl:choose>
			<xsl:when test="$token_string=''">
				<xsl:value-of select="$numberOfTokensCounted"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="getTotalNumberOfTokens">
					<xsl:with-param name="numberOfTokensCounted" select="number($numberOfTokensCounted)+1"/>
					<xsl:with-param name="token_string" select="substring-after($token_string, ')')"/>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		Checks for a previous instance of a user given the user's name as a default-user
		for a step, and then returns either 'yes' (if the user has already been recorded) or '' (if not).
	-->
	<xsl:template name="hasPreviousInstanceOfUser">
		<xsl:param name="username"/>
		<xsl:param name="position"/>
		
		<xsl:for-each select="/system-workflow-definition/steps/step[@default-user][position() &lt; $position]">
			<xsl:if test="@default-user='$username'">
				<xsl:text>yes</xsl:text>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>
	
	<xsl:template name="makePositionCell">
		<xsl:param name="position"/>
		<xsl:param name="step-id"/>
		<xsl:param name="step-label"/>
		<xsl:param name="node-number"/>
		<xsl:param name="is-last-step"/>
		
		<xsl:variable name="cellCoor">
			<xsl:call-template name="getPositionCoor">
				<xsl:with-param name="position" select="$position"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="xCenter" select="substring-before($cellCoor, ',')"/>
		<xsl:variable name="yCenter" select="substring-after($cellCoor, ',')"/>
		<xsl:variable name="x" select="number($xCenter)-floor($cell_width div 2)"/>
		<xsl:variable name="y" select="number($yCenter)-floor($cell_height div 2)"/>
		<xsl:choose>
			<xsl:when test="$is-last-step='true'">
				<rect x="{$x}" y="{$y}" width="{$cell_width}" height="{$cell_height}" style="fill:rgb(46,163,92);stroke:black;stroke-width:1;fill-opacity:1;stroke-opacity:1"/>
			</xsl:when>
			<xsl:otherwise>
				<rect x="{$x}" y="{$y}" width="{$cell_width}" height="{$cell_height}" style="fill:url(#blue_grad);stroke:black;stroke-width:1;fill-opacity:1;stroke-opacity:1"/>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:choose>
			<xsl:when test="string-length($step-label) != -1">
				<text x="{$xCenter}" y="{$yCenter+5}">
					<xsl:attribute name="style">
						<xsl:choose>
							<xsl:when test="string-length($step-label) &gt; 15">
								<xsl:value-of select="'fill:white; stroke:none;font-size:8pt;text-anchor:middle;'"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="'fill:white; stroke:none;font-size:10pt;text-anchor:middle;'"/>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:attribute>
					<!-- <xsl:value-of select="concat('(', $node-number, ') [', $position, ']')"/> -->
					<xsl:value-of select="$step-label"/>
				</text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:variable name="newText">
					<xsl:call-template name="getText">
						<xsl:with-param name="text" select="substring($step-label,25)"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="text1" select="substring-before($newText, '###%#')"/>
				<xsl:variable name="text2" select="substring-after($newText, '###%#')"/>
				<text x="{$xCenter}" y="{$yCenter - 5}" style="fill:white; stroke:none;font-size:8pt;text-anchor:middle;">
					<xsl:value-of select="$text1"/>
					<xsl:if test="$text1=''"><xsl:value-of select="$step-label"/></xsl:if>
				</text>
				<xsl:if test="$text1!=''">
					<text x="{$xCenter}" y="{$yCenter + 15}" style="fill:white; stroke:none;font-size:8pt;text-anchor:middle;">
						<xsl:value-of select="concat($text2, substring($step-label,25))"/>
					</text>
				</xsl:if>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template name="getText">
		<xsl:param name="text"/>
		<xsl:param name="prevText" select="''"/>
		
		<xsl:choose>
			<xsl:when test="substring-after($text, ' ')=''">
				<xsl:value-of select="concat($prevText, '###%#', $text)"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="getText">
					<xsl:with-param name="text" select="substring-after($text, ' ')"/>
					<xsl:with-param name="prevText" select="concat(substring-before($text, ' '), ' ')"/>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		Returns a string "x,y" where x is the center x-coordinate and y is the center y-coordinate of the step at $position, 
		where $position is a cell-position number.
	-->
	<xsl:template name="getPositionCoor">
		<xsl:param name="position"/>
		
		<xsl:variable name="xCenter">
			<xsl:choose>
				<xsl:when test="($position mod 5)=2 or ($position mod 5)=4">
					<xsl:value-of select="((($position - 1) mod 5)-1) * $horizontal_spacing + ($cell_width div 2) + $uniqueStep_xOffset + $margin"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="(($position - 1) mod 5) * $horizontal_spacing + ($cell_width div 2) + $margin"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="yCenter">
			<xsl:variable name="row" select="floor(($position - 1) div 5)"/>
			<xsl:choose>
				<xsl:when test="($position mod 5)=2 or ($position mod 5)=4">
					<xsl:value-of select="($row * $vertical_spacing) + ($cell_height div 2) + $uniqueStep_yOffset + $margin"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="($row * $vertical_spacing) + ($cell_height div 2) + $margin"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		
		<xsl:value-of select="concat($xCenter, ',', $yCenter)"/>
	</xsl:template>
	
	<!--
		Returns a string "x1,y1;x2,y2" where x1,y1 is the arrow-coordinate for the from-position and x2,y2 is the arrow
		coordinate for the to-position, where from-position and to-position are both cell-position numbers.
	-->
	<xsl:template name="getArrowCoors">
		<xsl:param name="from-position"/>
		<xsl:param name="to-position"/>
		
		<xsl:variable name="fromCoor">
			<xsl:call-template name="getPositionCoor">
				<xsl:with-param name="position" select="$from-position"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="fromCoorX" select="number(substring-before($fromCoor, ','))"/>
		<xsl:variable name="fromCoorY" select="number(substring-after($fromCoor, ','))"/>
		<xsl:variable name="toCoor">
			<xsl:call-template name="getPositionCoor">
				<xsl:with-param name="position" select="$to-position"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="toCoorX" select="number(substring-before($toCoor, ','))"/>
		<xsl:variable name="toCoorY" select="number(substring-after($toCoor, ','))"/>
		
		<xsl:choose>
			<xsl:when test="$fromCoorY = $toCoorY">
				<xsl:choose>
					<!--
					<xsl:when test="(number($from-position) - number($to-position) != 2) and (number($to-position) - number($from-position) != -2))">
						Arrow coors... I don't think I'll even call this template anymore 
					</xsl:when>
					-->
					<xsl:when test="$fromCoorX &lt; $toCoorX">
						<xsl:value-of select="concat($fromCoorX + ($cell_width div 2), ',', $fromCoorY, ';', $toCoorX - ($cell_width div 2), ',', $toCoorY)"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="concat($fromCoorX - ($cell_width div 2), ',', $fromCoorY, ';', $toCoorX + ($cell_width div 2), ',', $toCoorY)"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:when test="$fromCoorY &lt; $toCoorY">
				<xsl:value-of select="concat($fromCoorX, ',', $fromCoorY + ($cell_height div 2), ';', $toCoorX, ',', $toCoorY - ($cell_height div 2))"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="concat($fromCoorX, ',', $fromCoorY - ($cell_height div 2), ';', $toCoorX, ',', $toCoorY + ($cell_height div 2))"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!--
		was named: makeToArrow
		Returns 'x1,y1;x2,y2" where "x1,y1" is the from-node's arrow end coordinate and "x2,y2" is the to-node's arrow end coordinate
	-->	
	<xsl:template name="getArrowEndCoors">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="loaded-pointers"/>
		<xsl:param name="from-node"/>
		<xsl:param name="to-node"/>
		
		<xsl:variable name="from-cell-position">
			<xsl:call-template name="getPosition">
				<xsl:with-param name="node-content">
					<xsl:call-template name="getNodeByNumber">
						<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
						<xsl:with-param name="node-number" select="$from-node"/>
					</xsl:call-template>
				</xsl:with-param>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="from-pointer-region">
			<xsl:call-template name="getPointerRegion">
				<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
				<xsl:with-param name="cell-position" select="$from-cell-position"/>
				<xsl:with-param name="pointer-node-number" select="$to-node"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="from-pointer-region-content">
			<xsl:call-template name="getPointerRegionContent">
				<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
				<xsl:with-param name="node-number" select="$from-node"/>
				<xsl:with-param name="region" select="$from-pointer-region"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="from-offset">
			<xsl:call-template name="getOffset">
				<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
				<xsl:with-param name="node-number" select="$from-node"/>
				<xsl:with-param name="pointer-region" select="$from-pointer-region"/>
				<xsl:with-param name="pointer" select="concat('t', $to-node)"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:variable name="fromCoor">
			<xsl:call-template name="getPositionCoor">
				<xsl:with-param name="position" select="$from-cell-position"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="fromCoorX" select="substring-before($fromCoor, ',')"/>
		<xsl:variable name="fromCoorY" select="substring-after($fromCoor, ',')"/>
		<xsl:variable name="from-side">
			<xsl:choose>
				<xsl:when test="$from-pointer-region='top-mid' or $from-pointer-region='top-left' or $from-pointer-region='top-right'">top</xsl:when>
				<xsl:when test="$from-pointer-region='bottom-mid' or $from-pointer-region='bottom-left' or $from-pointer-region='bottom-right'">bottom</xsl:when>
				<xsl:when test="$from-pointer-region='left' or $from-pointer-region='right'">
					<xsl:value-of select="$from-pointer-region"/>
				</xsl:when>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="rendered-fromCoor">
			<xsl:choose>
				<xsl:when test="$from-side='top'">
					<xsl:value-of select="concat(number($fromCoorX) + number($from-offset), ',', number($fromCoorY) - (($cell_height div 2) + $cell-y-margin))"/>
				</xsl:when>
				<xsl:when test="$from-side='left'">
					<xsl:value-of select="concat(number($fromCoorX) - (($cell_width div 2) + $cell-x-margin), ',', number($fromCoorY) + number($from-offset))"/>
				</xsl:when>
				<xsl:when test="$from-side='right'">
					<xsl:value-of select="concat(number($fromCoorX) + ($cell_width div 2) + $cell-x-margin, ',', number($fromCoorY) + number($from-offset))"/>
				</xsl:when>
				<xsl:when test="$from-side='bottom'">
					<xsl:value-of select="concat(number($fromCoorX) + number($from-offset), ',', number($fromCoorY) + (($cell_height div 2) + $cell-y-margin))"/>
				</xsl:when>
			</xsl:choose>
		</xsl:variable>
		
		
		<xsl:variable name="to-cell-position">
			<xsl:call-template name="getPosition">
				<xsl:with-param name="node-content">
					<xsl:call-template name="getNodeByNumber">
						<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
						<xsl:with-param name="node-number" select="$to-node"/>
					</xsl:call-template>
				</xsl:with-param>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="to-pointer-region">
			<xsl:call-template name="getPointerRegion">
				<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
				<xsl:with-param name="cell-position" select="$to-cell-position"/>
				<xsl:with-param name="pointer-node-number" select="$from-node"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="to-pointer-region-content">
			<xsl:call-template name="getPointerRegionContent">
				<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
				<xsl:with-param name="node-number" select="$to-node"/>
				<xsl:with-param name="region" select="$to-pointer-region"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="to-offset">
			<xsl:call-template name="getOffset">
				<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
				<xsl:with-param name="node-number" select="$to-node"/>
				<xsl:with-param name="pointer-region" select="$to-pointer-region"/>
				<xsl:with-param name="pointer" select="concat('f', $from-node)"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:variable name="toCoor">
			<xsl:call-template name="getPositionCoor">
				<xsl:with-param name="position" select="$to-cell-position"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="toCoorX" select="substring-before($toCoor, ',')"/>
		<xsl:variable name="toCoorY" select="substring-after($toCoor, ',')"/>
		<xsl:variable name="to-side">
			<xsl:choose>
				<xsl:when test="$to-pointer-region='top-mid' or $to-pointer-region='top-left' or $to-pointer-region='top-right'">top</xsl:when>
				<xsl:when test="$to-pointer-region='bottom-mid' or $to-pointer-region='bottom-left' or $to-pointer-region='bottom-right'">bottom</xsl:when>
				<xsl:when test="$to-pointer-region='left' or $to-pointer-region='right'">
					<xsl:value-of select="$to-pointer-region"/>
				</xsl:when>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="rendered-toCoor">
			<xsl:choose>
				<xsl:when test="$to-side='top'">
					<xsl:value-of select="concat(number($toCoorX) + number($to-offset), ',', number($toCoorY) - (($cell_height div 2) + $cell-y-margin))"/>
				</xsl:when>
				<xsl:when test="$to-side='left'">
					<xsl:value-of select="concat(number($toCoorX) - (($cell_width div 2) + $cell-x-margin), ',', number($toCoorY) + number($to-offset))"/>
				</xsl:when>
				<xsl:when test="$to-side='right'">
					<xsl:value-of select="concat(number($toCoorX) + ($cell_width div 2) + $cell-x-margin, ',', number($toCoorY) + number($to-offset))"/>
				</xsl:when>
				<xsl:when test="$to-side='bottom'">
					<xsl:value-of select="concat(number($toCoorX) + number($to-offset), ',', number($toCoorY) + (($cell_height div 2) + $cell-y-margin))"/>
				</xsl:when>
			</xsl:choose>
		</xsl:variable>
		
		<xsl:value-of select="concat($rendered-fromCoor, ';', $rendered-toCoor)"/>
	</xsl:template>
	
	<xsl:template name="getOffset">
		<xsl:param name="loaded-pointers"/>
		<xsl:param name="node-number"/>
		<xsl:param name="pointer-region"/>
		<xsl:param name="pointer"/>
		
		<xsl:variable name="increment" select="number(20)"/>
		
		<xsl:variable name="pointer-region-content">
			<xsl:call-template name="getPointerRegionContent">
				<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
				<xsl:with-param name="node-number" select="$node-number"/>
				<xsl:with-param name="region" select="$pointer-region"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:variable name="pointer-count">
			<xsl:call-template name="countArray">
				<xsl:with-param name="array" select="$pointer-region-content"/>
				<xsl:with-param name="separator" select="','"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="pointer-index">
			<xsl:call-template name="getFirstIndex">
				<xsl:with-param name="array" select="$pointer-region-content"/>
				<xsl:with-param name="separator" select="','"/>
				<xsl:with-param name="value" select="$pointer"/>
			</xsl:call-template>
		</xsl:variable>
		<!--
		loaded-pointers = <xsl:value-of select="$loaded-pointers"/>
		pointer-region-content = <xsl:value-of select="$pointer-region-content"/>
		pointer-region = <xsl:value-of select="$pointer-region"/>
		pointer-index = <xsl:value-of select="$pointer-index"/>
		pointer-count = <xsl:value-of select="$pointer-count"/>
		-->
		<xsl:choose>
			<xsl:when test="$pointer-region='bottom-mid' or $pointer-region='top-mid'">
				<xsl:choose>
					<xsl:when test="$pointer-count=1">
						<xsl:value-of select="number(0)"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:choose>
							<xsl:when test="$pointer-index=1">
								<xsl:value-of select="number(-5)"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="number(5)"/>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:when test="$pointer-region='bottom-right' or $pointer-region='top-right'">
				<xsl:value-of select="$increment + (number($pointer-index) - 1) * $increment"/>
			</xsl:when>
			<xsl:when test="$pointer-region='bottom-left' or $pointer-region='top-left'">
				<xsl:value-of select="number(-1) * ($increment + (($pointer-count - $pointer-index) * $increment))"/>
			</xsl:when>
			<xsl:when test="$pointer-region='left' or $pointer-region='right'">
				<xsl:choose>
					<xsl:when test="$pointer-count=1">
						<xsl:value-of select="number(0)"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:choose>
							<xsl:when test="$pointer-index=1">
								<xsl:value-of select="number(-5)"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="number(5)"/>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template name="countArray">
		<xsl:param name="array"/>
		<xsl:param name="separator"/>
		<xsl:param name="count" select="number(0)"/>
		
		<xsl:choose>
			<xsl:when test="$array=''">
				<xsl:value-of select="$count"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="countArray">
					<xsl:with-param name="array" select="substring-after($array, $separator)"/>
					<xsl:with-param name="separator" select="$separator"/>
					<xsl:with-param name="count" select="$count + 1"/>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!--
		Returns the first index (index starts at 1, NOT 0) of the value in the array or -1 if not found
	-->
	<xsl:template name="getFirstIndex">
		<xsl:param name="array"/>
		<xsl:param name="separator"/>
		<xsl:param name="value"/>
		<xsl:param name="index" select="number(1)"/>
		
		<xsl:choose>
			<xsl:when test="$array=''">
				<xsl:value-of select="number(-1)"/>
			</xsl:when>
			<xsl:when test="substring-before($array, $separator)=$value">
				<xsl:value-of select="$index"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="getFirstIndex">
					<xsl:with-param name="array" select="substring-after($array, $separator)"/>
					<xsl:with-param name="separator" select="$separator"/>
					<xsl:with-param name="value" select="$value"/>
					<xsl:with-param name="index" select="$index + 1"/>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template name="drawArrowPath">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="loaded-pointers"/>
		<xsl:param name="from-node"/>
		<xsl:param name="to-node"/>
		
		<xsl:variable name="arrow-end-coors">
			<xsl:call-template name="getArrowEndCoors">
				<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
				<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
				<xsl:with-param name="from-node" select="$from-node"/>
				<xsl:with-param name="to-node" select="$to-node"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:variable name="x1" select="substring-before($arrow-end-coors, ',')"/>
		<xsl:variable name="y1" select="substring-before(substring-after($arrow-end-coors, ','), ';')"/>
		<xsl:variable name="x2" select="substring-before(substring-after($arrow-end-coors, ';'), ',')"/>
		<xsl:variable name="y2" select="substring-after(substring-after($arrow-end-coors, ';'), ',')"/>
		
		<xsl:variable name="from-position">
			<xsl:call-template name="getPosition">
				<xsl:with-param name="node-content">
					<xsl:call-template name="getNodeByNumber">
						<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
						<xsl:with-param name="node-number" select="$from-node"/>
					</xsl:call-template>
				</xsl:with-param>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="to-position">
			<xsl:call-template name="getPosition">
				<xsl:with-param name="node-content">
					<xsl:call-template name="getNodeByNumber">
						<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
						<xsl:with-param name="node-number" select="$to-node"/>
					</xsl:call-template>
				</xsl:with-param>
			</xsl:call-template>
		</xsl:variable>
		
		
		<xsl:comment>
			to-position, positionCoor:
			<xsl:call-template name="getPositionCoor">
				<xsl:with-param name="position" select="$to-position"/>
			</xsl:call-template>
			y-padding: <xsl:value-of select="number($cell_height div 2) + $cell-y-margin"/>
			offset:
				<xsl:call-template name="getOffset">
					<xsl:with-param name="loaded-pointers" select="$loaded-pointers"/>
					<xsl:with-param name="node-number" select="'9'"/>
					<xsl:with-param name="pointer-region" select="'top-right'"/>
					<xsl:with-param name="pointer" select="'t3'"/>
				</xsl:call-template>
			<xsl:if test="$from-node='9' and $to-node='3'">******JHERE*****</xsl:if>
		</xsl:comment>
		
		
		<xsl:variable name="fromCoor">
			<xsl:call-template name="getPositionCoor">
				<xsl:with-param name="position" select="$from-position"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="fromCoorX" select="number(substring-before($fromCoor, ','))"/>
		<xsl:variable name="fromCoorY" select="number(substring-after($fromCoor, ','))"/>
		<xsl:variable name="toCoor">
			<xsl:call-template name="getPositionCoor">
				<xsl:with-param name="position" select="$to-position"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="toCoorX" select="number(substring-before($toCoor, ','))"/>
		<xsl:variable name="toCoorY" select="number(substring-after($toCoor, ','))"/>
		<xsl:comment>
			$from-node = <xsl:value-of select="$from-node"/>
			$to-node = <xsl:value-of select="$to-node"/>
			$arrow-end-coors: <xsl:value-of select="$arrow-end-coors"/>
			$fromCoorY: <xsl:value-of select="$fromCoorY"/>
			$toCoorY = <xsl:value-of select="$toCoorY"/>
			$from-position = <xsl:value-of select="$from-position"/>
			$to-position = <xsl:value-of select="$to-position"/>
		</xsl:comment>
		
		<!-- Checks if there is a unique-edit-step blocking a particular kind of arrow noStepBlock='true' means there is no block -->
		<xsl:variable name="noStepBlock">
			<xsl:choose>
				<xsl:when test="$from-position = $to-position + 8 or $to-position = $from-position + 8">
					<xsl:variable name="bottom-position">
						<xsl:choose>
							<xsl:when test="number($from-position) &gt; number($to-position)">
								<xsl:value-of select="$from-position"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="$to-position"/>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:variable>
					<xsl:call-template name="isAvailablePosition">
						<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
						<xsl:with-param name="cell-position" select="number($bottom-position)-4"/>
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>true</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		
		<xsl:choose>
			<!-- This test indicates that the two cells are on the same row if true -->
			<xsl:when test="$fromCoorY = $toCoorY">
				<xsl:choose>
					<!-- If there is a cell position between the two cells -->
					<xsl:when test="(number($from-position)-number($to-position)=number(4)) or (number($from-position)-number($to-position)=number(-4))">
						<!-- Find the left-most cell-position -->
						<xsl:variable name="left-position">
							<xsl:choose>
								<xsl:when test="$from-position &lt; $to-position"><xsl:value-of select="$from-position"/></xsl:when>
								<xsl:otherwise><xsl:value-of select="$to-position"/></xsl:otherwise>
							</xsl:choose>
						</xsl:variable>
						<!-- Find if the cell position between the two cells blocks linking the two cells together -->
						<xsl:variable name="obstruction">
							<xsl:variable name="isAvailable">
								<xsl:call-template name="isAvailablePosition">
									<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
									<xsl:with-param name="cell-position" select="number($left-position)+2"/>
								</xsl:call-template>
							</xsl:variable>
							<xsl:choose>
								<xsl:when test="$isAvailable='true'">false</xsl:when>
								<xsl:otherwise>true</xsl:otherwise>
							</xsl:choose>
						</xsl:variable>
						<xsl:comment>
							$obstruction = <xsl:value-of select="$obstruction"/>
						</xsl:comment>
						<xsl:choose>
							<!-- When there is a step in the way of the two cells -->
							<xsl:when test="$obstruction='true'">
								<xsl:choose>
									<xsl:when test="$fromCoorX &lt; $toCoorX">
										<path d="{concat('M', $x1, ',', $y1, ' C', $x1 + $anchor_xOffset, ',', $y1 - $anchor_yOffset, ' ', $x2 - $anchor_xOffset, ',', $y2 - $anchor_yOffset, ' ', $x2, ',', $y2)}" style="{$line-style}" marker-mid="url(#arrowhead)" marker-end="url(#arrowhead)"/>
									</xsl:when>
									<xsl:otherwise>
										<path d="{concat('M', $x1, ',', $y1, ' C', $x1 - $anchor_xOffset, ',', $y1 - $anchor_yOffset, ' ', $x2 + $anchor_xOffset, ',', $y2 - $anchor_yOffset, ' ', $x2, ',', $y2)}" style="{$line-style}" marker-mid="url(#arrowhead)" marker-end="url(#arrowhead)"/>
									</xsl:otherwise>
								</xsl:choose>
							</xsl:when>
							<xsl:otherwise>
								<xsl:choose>
									<xsl:when test="$fromCoorX &lt; $toCoorX">
										<path d="{concat('M', $x1, ',', $y1, ' L', $x2, ',', $y2)}" style="{$line-style}" marker-mid="url(#arrowhead)" marker-end="url(#arrowhead)"/>
									</xsl:when>
									<xsl:otherwise>
										<path d="{concat('M', $x1, ',', $y1, ' L', $x2, ',', $y2)}" style="{$line-style}" marker-mid="url(#arrowhead)" marker-end="url(#arrowhead)"/>
									</xsl:otherwise>
								</xsl:choose>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:when>
					<xsl:when test="$fromCoorX &lt; $toCoorX">
						<path d="{concat('M', $x1, ',', $y1, ' L', $x2, ',', $y2)}" style="{$line-style}" marker-mid="url(#arrowhead)" marker-end="url(#arrowhead)"/>
					</xsl:when>
					<xsl:otherwise>
						<path d="{concat('M', $x1, ',', $y1, ' L', $x2, ',', $y2)}" style="{$line-style}" marker-mid="url(#arrowhead)" marker-end="url(#arrowhead)"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<!-- When the steps are on top of each other, make sure that other steps aren't blocking the arrow path -->
			<!--<xsl:when test="$fromCoorX = $toCoorX">
				Could there possibly be more than 3 rows? If not, then hardcoding would make this code much easier to write
				****NEEDS CODING TO FIX ARROW OVERLAP ISSUES
			</xsl:when>
			-->
			<!-- If from-node is above (but not directly) to-node or if to-node is above (but not directly) from-node -->
			<xsl:when test="$fromCoorX = $toCoorX and $from-position != $to-position + 5 and $from-position != $to-position - 5">
				<xsl:choose>
					<!-- going up -->
					<xsl:when test="$fromCoorY &gt; $toCoorY">
						<path d="{concat('M', $x1, ',', $y1, ' C', $x1 - $anchor_xOffset, ',', $y1 - $anchor_yOffset, ' ', $x2 - $anchor_xOffset, ',', $y2 + $anchor_yOffset, ' ', $x2, ',', $y2)}" style="{$line-style}" marker-mid="url(#arrowhead)" marker-end="url(#arrowhead)"/>
					</xsl:when>
					<!-- going down -->
					<xsl:when test="$fromCoorY &lt; $toCoorY">
						<path d="{concat('M', $x1, ',', $y1, ' C', $x1 - $anchor_xOffset, ',', $y1 + $anchor_yOffset, ' ', $x2 - $anchor_xOffset, ',', $y2 - $anchor_yOffset, ' ', $x2, ',', $y2)}" style="{$line-style}" marker-mid="url(#arrowhead)" marker-end="url(#arrowhead)"/>
					</xsl:when>
				</xsl:choose>
			</xsl:when>
			<xsl:when test="$noStepBlock='false'">
				<xsl:choose>
					<!-- going up -->
					<xsl:when test="$fromCoorY &gt; $toCoorY">
							<path d="{concat('M', $x1, ',', $y1, ' C', $x1 + ($anchor_xOffset * 3), ',', $y1 - ($anchor_yOffset * 2), ' ', $x2 - ($anchor_xOffset), ',', $y2 + ($anchor_yOffset), ' ', $x2, ',', $y2)}" style="{$line-style}" marker-mid="url(#arrowhead)" marker-end="url(#arrowhead)"/>
					</xsl:when>
					<!-- going down -->
					<xsl:when test="$fromCoorY &lt; $toCoorY">
							<path d="{concat('M', $x1, ',', $y1, ' C', $x1 - ($anchor_xOffset * 3), ',', $y1 + ($anchor_yOffset * 2), ' ', $x2 + ($anchor_xOffset), ',', $y2 - ($anchor_yOffset), ' ', $x2, ',', $y2)}" style="{$line-style}" marker-mid="url(#arrowhead)" marker-end="url(#arrowhead)"/>
					</xsl:when>
				</xsl:choose>
			</xsl:when>
			<!-- If drawing a down-arrow -->
			<xsl:when test="$fromCoorY &lt; $toCoorY">
				<path d="{concat('M', $x1, ',', $y1, ' L', $x2, ',', $y2)}" style="{$line-style}" marker-mid="url(#arrowhead)" marker-end="url(#arrowhead)"/>
			</xsl:when>
			<!-- If drawing an up-arrow -->
			<xsl:otherwise>
				<path d="{concat('M', $x1, ',', $y1, ' L', $x2, ',', $y2)}" style="{$line-style}" marker-mid="url(#arrowhead)" marker-end="url(#arrowhead)"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template name="drawArrowPathOld">
		<xsl:param name="loaded-steps"/>
		<xsl:param name="loaded-pointers"/>
		<xsl:param name="from-position"/>
		<xsl:param name="to-position"/>
		
		<xsl:variable name="fromCoor">
			<xsl:call-template name="getPositionCoor">
				<xsl:with-param name="position" select="$from-position"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="fromCoorX" select="number(substring-before($fromCoor, ','))"/>
		<xsl:variable name="fromCoorY" select="number(substring-after($fromCoor, ','))"/>
		<xsl:variable name="toCoor">
			<xsl:call-template name="getPositionCoor">
				<xsl:with-param name="position" select="$to-position"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="toCoorX" select="number(substring-before($toCoor, ','))"/>
		<xsl:variable name="toCoorY" select="number(substring-after($toCoor, ','))"/>
		
		<xsl:comment>
			$fromCoorY: <xsl:value-of select="$fromCoorY"/>
			$toCoorY = <xsl:value-of select="$toCoorY"/>
			$from-position = <xsl:value-of select="$from-position"/>
			$to-position = <xsl:value-of select="$to-position"/>
		</xsl:comment>
		
		<xsl:choose>
			<!-- This test indicates that the two cells are on the same row if true -->
			<xsl:when test="$fromCoorY = $toCoorY">
				<xsl:comment>
					$fromCoorY = $toCoorY
					number($from-position) - number($to-position) = <xsl:value-of select="number($from-position) - number($to-position)"/>
					<xsl:if test="number($from-position)-number($to-position)=number(-4)">
						Yes!
					</xsl:if>
				</xsl:comment>
				<xsl:choose>
					<!-- If there is a cell position between the two cells -->
					<xsl:when test="(number($from-position)-number($to-position)=number(4)) or (number($from-position)-number($to-position)=number(-4))">
						<xsl:comment>IT IS IN SCOPE</xsl:comment>
						<!-- Find the left-most cell-position -->
						<xsl:variable name="left-position">
							<xsl:choose>
								<xsl:when test="$from-position &lt; $to-position"><xsl:value-of select="$from-position"/></xsl:when>
								<xsl:otherwise><xsl:value-of select="$to-position"/></xsl:otherwise>
							</xsl:choose>
						</xsl:variable>
						<!-- Find if the cell position between the two cells blocks linking the two cells together -->
						<xsl:variable name="obstruction">
							<xsl:variable name="isAvailable">
								<xsl:call-template name="isAvailablePosition">
									<xsl:with-param name="loaded-steps" select="$loaded-steps"/>
									<xsl:with-param name="cell-position" select="number($left-position)+2"/>
								</xsl:call-template>
							</xsl:variable>
							<xsl:choose>
								<xsl:when test="$isAvailable='true'">false</xsl:when>
								<xsl:otherwise>true</xsl:otherwise>
							</xsl:choose>
						</xsl:variable>
						<xsl:comment>
							$obstruction = <xsl:value-of select="$obstruction"/>
						</xsl:comment>
						<xsl:choose>
							<!-- When there is a step in the way of the two cells -->
							<xsl:when test="$obstruction='true'">
								<xsl:choose>
									<xsl:when test="$fromCoorX &lt; $toCoorX">
										<xsl:variable name="x1" select="$fromCoorX"/>
										<xsl:variable name="y1" select="$fromCoorY - (($cell_height div 2))"/>
										<xsl:variable name="x2" select="$toCoorX"/>
										<xsl:variable name="y2" select="$toCoorY - (($cell_height div 2) + $cell-y-margin)"/>
										<path d="{concat('M', $x1, ',', $y1, ' C', $x1 + $anchor_xOffset, ',', $y1 - $anchor_yOffset, ' ', $x2 - $anchor_xOffset, ',', $y2 - $anchor_yOffset, ' ', $x2, ',', $y2)}" style="{$line-style}" marker-mid="url(#arrowhead)" marker-end="url(#arrowhead)"/>
									</xsl:when>
									<xsl:otherwise>
										<xsl:variable name="x1" select="$fromCoorX"/>
										<xsl:variable name="y1" select="$fromCoorY - (($cell_height div 2))"/>
										<xsl:variable name="x2" select="$toCoorX"/>
										<xsl:variable name="y2" select="$toCoorY - (($cell_height div 2) + $cell-y-margin)"/>
										<path d="{concat('M', $x1, ',', $y1, ' C', $x1 - $anchor_xOffset, ',', $y1 - $anchor_yOffset, ' ', $x2 + $anchor_xOffset, ',', $y2 - $anchor_yOffset, ' ', $x2, ',', $y2)}" style="{$line-style}" marker-mid="url(#arrowhead)" marker-end="url(#arrowhead)"/>
									</xsl:otherwise>
								</xsl:choose>
							</xsl:when>
							<xsl:otherwise>
								<xsl:choose>
									<xsl:when test="$fromCoorX &lt; $toCoorX">
										<xsl:variable name="x1" select="$fromCoorX + (($cell_width div 2))"/>
										<xsl:variable name="y1" select="$fromCoorY"/>
										<xsl:variable name="x2" select="$toCoorX - (($cell_width div 2) + $cell-x-margin)"/>
										<xsl:variable name="y2" select="$toCoorY"/>
										<path d="{concat('M', $x1, ',', $y1, ' L', $x2, ',', $y2)}" style="{$line-style}" marker-mid="url(#arrowhead)" marker-end="url(#arrowhead)"/>
									</xsl:when>
									<xsl:otherwise>
										<xsl:variable name="x1" select="$fromCoorX - (($cell_width div 2))"/>
										<xsl:variable name="y1" select="$fromCoorY"/>
										<xsl:variable name="x2" select="$toCoorX + (($cell_width div 2) + $cell-x-margin)"/>
										<xsl:variable name="y2" select="$t