<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xt="http://www.jclark.com/xt"
		version="1.0">

<xsl:template match="Go">
	<xsl:call-template name="Go2">
	<xsl:with-param name="TMS">
	<Go>
<Instruction CurrentState="A" CurrentSymbol="b" NextSymbol="." NextState="Z" Move="R">
<Instruction CurrentState="A" CurrentSymbol="1" NextSymbol="2" NextState="A" Move="R">
</Instruction>
</Instruction>
		<State>A</State>
		<xsl:copy-of select="TapeLeft"/>
		<xsl:copy-of select="Symbol"/>
		<xsl:copy-of select="TapeRight"/>
	</Go>
	</xsl:with-param>
	</xsl:call-template>

</xsl:template>

<!--============================================-->

<xsl:template name="Go2"> 
<xsl:param name="TMS"/>
<xsl:for-each select="xt:node-set($TMS)/Go">

<xsl:choose>

<xsl:when test="State='Z'">
	<xsl:copy-of select="TapeLeft"/>
	<xsl:copy-of select="Symbol"/>
	<xsl:copy-of select="TapeRight"/>
</xsl:when>

<xsl:otherwise>
	<xsl:call-template name="Go2">
	<xsl:with-param name="TMS">
	<Go>
	<xsl:copy-of select="Instruction"/>
		<xsl:call-template name="Step">
		<xsl:with-param name="TMS">
		<Go>
			<xsl:copy-of select="Instruction"/>
			<xsl:copy-of select="State"/>
			<xsl:copy-of select="TapeLeft"/>
			<xsl:copy-of select="Symbol"/>
			<xsl:copy-of select="TapeRight"/>
		</Go>
		</xsl:with-param>
		</xsl:call-template>
	</Go>
	</xsl:with-param>
	</xsl:call-template>
</xsl:otherwise>

</xsl:choose>
</xsl:for-each>
</xsl:template>

<!--===============================================-->
<xsl:template name="Step">
  <xsl:param name="TMS"/>
<xsl:for-each select="xt:node-set($TMS)/Go">

<xsl:choose>

<xsl:when test="Instruction/@CurrentState=State">
	<xsl:choose>
	<xsl:when test="Instruction/@CurrentSymbol=Symbol">
		<xsl:choose>
		<xsl:when test="Instruction/@Move='R'">
			<State>
				<xsl:value-of select="Instruction/@NextState"/>
			</State>
			<TapeLeft>
				<Nod>
				<Square>
				<xsl:value-of select="Instruction/@NextSymbol"/>
				</Square>
				<xsl:copy-of select="TapeLeft/Nod"/>
				</Nod>
			</TapeLeft>
			<Symbol>
				<xsl:value-of select="TapeRight/Nod/Square"/>
			</Symbol>
			<TapeRight>
				<xsl:copy-of select="TapeRight/Nod/Nod"/>
			</TapeRight>
		</xsl:when>

		<xsl:when test="Instruction/@Move='L'">
			<State>
				<xsl:value-of select="Instruction/@NextState"/>
			</State>
			<TapeLeft>
				<xsl:copy-of select="TapeLeft/Nod/Nod"/>
			</TapeLeft>
			<Symbol>
				<xsl:value-of select="TapeLeft/Nod/Square"/>
			</Symbol>
			<TapeRight>
				<Nod>
				<Square>
				<xsl:value-of select="Instruction/@NextSymbol"/>
				</Square>
				<xsl:copy-of select="TapeRight/Nod"/>
				</Nod>
			</TapeRight>
		</xsl:when>
		</xsl:choose>
	</xsl:when>

	<xsl:otherwise>
		<xsl:call-template name="Step">
		<xsl:with-param name="TMS">
		<Go>
			<xsl:copy-of select="Instruction/Instruction"/>
			<xsl:copy-of select="State"/>
			<xsl:copy-of select="TapeLeft"/>
			<xsl:copy-of select="Symbol"/>
			<xsl:copy-of select="TapeRight"/>
		</Go>
		</xsl:with-param>
		</xsl:call-template>
	</xsl:otherwise>
	</xsl:choose>
</xsl:when>

<xsl:otherwise>
	<xsl:call-template name="Step">
	<xsl:with-param name="TMS">
	<Go>
		<xsl:copy-of select="Instruction/Instruction"/>
		<xsl:copy-of select="State"/>
		<xsl:copy-of select="TapeLeft"/>
		<xsl:copy-of select="Symbol"/>
		<xsl:copy-of select="TapeRight"/>
	</Go>
	</xsl:with-param>
	</xsl:call-template>
</xsl:otherwise>

</xsl:choose>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>