You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by jb...@apache.org on 2010/06/12 21:38:36 UTC

svn commit: r954088 - /commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/computeLCA.xsl

Author: jbeard
Date: Sat Jun 12 19:38:36 2010
New Revision: 954088

URL: http://svn.apache.org/viewvc?rev=954088&view=rev
Log:
computLCA.xsl now looks to be correct.

Modified:
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/computeLCA.xsl

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/computeLCA.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/computeLCA.xsl?rev=954088&r1=954087&r2=954088&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/computeLCA.xsl (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/computeLCA.xsl Sat Jun 12 19:38:36 2010
@@ -79,59 +79,97 @@
 		</xsl:if>
 	</xsl:template>
 
+
+	<xsl:template match="c:target">
+		<xsl:param name="lca"/>
+
+		<!-- get the target state -->
+		<xsl:variable name="targetId" select="./c:targetState/text()"/>
+		<xsl:variable name="targetState" select="//*[(self::s:state or self::s:parallel or self::s:final or self::s:initial or self::s:scxml or self::s:history) and @id = $targetId]"/>
+
+		<!--
+		<xsl:message>
+			<xsl:text>In template match="c:target"</xsl:text>
+			<xsl:text>&#10;</xsl:text>
+			<xsl:text>targetId: </xsl:text>
+			<xsl:value-of select="$targetId"/>
+			<xsl:text>&#10;</xsl:text>
+			<xsl:text>targetState: </xsl:text>
+			<xsl:value-of select="$targetState/@id"/>
+			<xsl:text>&#10;</xsl:text>
+			<xsl:text>lca: </xsl:text>
+			<xsl:value-of select="$lca/@id"/>
+			<xsl:text>&#10;</xsl:text>
+		</xsl:message>
+		-->
+
+		<xsl:copy>
+			<xsl:apply-templates select="@*"/>
+
+			<c:enterpath>
+				<xsl:call-template name="genStateTree">
+					<xsl:with-param name="current" select="$targetState"/>
+					<xsl:with-param name="end" select="$lca"/>
+				</xsl:call-template>
+			</c:enterpath>
+
+			<xsl:apply-templates select="node()"/>
+		</xsl:copy>
+	</xsl:template>
+
+	<!-- identity transform -->
+	<xsl:template match="c:targets">
+		<xsl:param name="lca"/>
+
+		<xsl:copy>
+			<xsl:apply-templates select="@*|node()">
+				<xsl:with-param name="lca" select="$lca"/>
+			</xsl:apply-templates>
+		</xsl:copy>
+	</xsl:template>
+
 	<xsl:template match="s:transition">
 
 		<xsl:variable name="srcState" select="parent::*"/>
 
+		<xsl:variable name="firstTargetStateId" select="c:targets/c:target/c:targetState/text()[1]"/>
+		<xsl:variable name="firstTargetState" select="//*[(self::s:state or self::s:parallel or self::s:final or self::s:initial or self::s:scxml or self::s:history) and @id = $firstTargetStateId]"/>
+
+		<!-- compute the least common ancestor using the Kaysian method for intersection-->
+		<!-- http://stackoverflow.com/questions/538293/find-common-parent-using-xpath -->
+		<xsl:variable name="lca" 
+			select="$srcState/ancestor::* [count(. | $firstTargetState/ancestor::*) = count($firstTargetState/ancestor::*) ] [1]" />
+
 		<xsl:copy>
 
 			<xsl:apply-templates select="@*"/>
 
-			<xsl:for-each select="./c:targets/c:target">
-				<!-- get the target state -->
-				<xsl:variable name="targetId" select="."/>
-				<xsl:variable name="targetState" select="//*[(self::s:state or self::s:parallel or self::s:final or self::s:initial or self::s:scxml or self::s:history) and @id = $targetId]"/>
-
-				<!-- compute the least common ancestor using the Kaysian method for intersection-->
-				<!-- http://stackoverflow.com/questions/538293/find-common-parent-using-xpath -->
-				<xsl:variable name="lca" select="$srcState/ancestor::* [count(. | $targetState/ancestor::*) = count($targetState/ancestor::*) ] [1]" />
-
-				<!-- call recursive function to populate exit and entry paths -->
-				<!--
-				<xsl:message>
-					<xsl:text>START&#10;</xsl:text>
-					<xsl:text>srcState: </xsl:text>
-					<xsl:value-of select="$srcState/@id"/>
-					<xsl:text>&#10;</xsl:text>
-				</xsl:message>
-				-->
-
-				<c:exitpath>
-					<xsl:call-template name="genStateTree">
-						<xsl:with-param name="current" select="$srcState"/>
-						<xsl:with-param name="end" select="$lca"/>
-					</xsl:call-template>
-				</c:exitpath>
-
-				<!--
-				<xsl:message>
-					<xsl:text>END&#10;</xsl:text>
-				</xsl:message>
-				-->
-
-				<c:enterpath>
-					<xsl:call-template name="genStateTree">
-						<xsl:with-param name="current" select="$targetState"/>
-						<xsl:with-param name="end" select="$lca"/>
-					</xsl:call-template>
-				</c:enterpath>
-				<c:lca>
-					<xsl:value-of select="$lca/@id"/>
-				</c:lca>
+			<!-- call recursive function to populate exit and entry paths -->
+			<!--
+			<xsl:message>
+				<xsl:text>START&#10;</xsl:text>
+				<xsl:text>srcState: </xsl:text>
+				<xsl:value-of select="$srcState/@id"/>
+				<xsl:text>&#10;</xsl:text>
+			</xsl:message>
+			-->
+
+			<c:exitpath>
+				<xsl:call-template name="genStateTree">
+					<xsl:with-param name="current" select="$srcState"/>
+					<xsl:with-param name="end" select="$lca"/>
+				</xsl:call-template>
+			</c:exitpath>
+
+			<c:lca>
+				<xsl:value-of select="$lca/@id"/>
+			</c:lca>
+
+			<xsl:apply-templates select="c:targets">
+				<xsl:with-param name="lca" select="$lca"/>
+			</xsl:apply-templates>
 
-			</xsl:for-each>
-
-			<xsl:apply-templates select="node()"/>
+			<xsl:apply-templates select="node()[not(self::c:targets)]"/>
 		</xsl:copy>
 
 	</xsl:template>