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:39:48 UTC

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

Author: jbeard
Date: Sat Jun 12 19:39:47 2010
New Revision: 954098

URL: http://svn.apache.org/viewvc?rev=954098&view=rev
Log:
test/xslt/numberStatesAndTransitions.xsl now works correctly.

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

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/numberStatesAndTransitions.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/numberStatesAndTransitions.xsl?rev=954098&r1=954097&r2=954098&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/numberStatesAndTransitions.xsl (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/numberStatesAndTransitions.xsl Sat Jun 12 19:39:47 2010
@@ -7,20 +7,6 @@
 	<xsl:output method="xml"/>
 
 	<!-- we copy them, so that we can use their positions as identifiers -->
-	<xsl:variable name="states" 
-		select="//*[self::s:state or self::s:parallel or self::s:final or self::s:initial or self::s:history]" />
-
-	<xsl:variable name="transitions" select="//s:transition"/>
-
-	<!--
-	<xsl:template match="/">
-		<xsl:for-each select="$states">
-			<xsl:message>
-				position: <xsl:value-of select="position()"/>
-			</xsl:message>
-		</xsl:for-each>
-	</xsl:template>
-	-->
 
 	<!-- identity transform -->
 	<xsl:template match="@*|node()">
@@ -31,16 +17,23 @@
 
 	<xsl:template match="s:state | s:parallel | s:final | s:initial | s:history">
 
-		<xsl:variable name="stateId">
-			<xsl:value-of select="@id"/>
-		</xsl:variable>
-
 		<!-- what we want to ask is, what is his position in the nodeset that we've constructed? 
 			but we can't use position normally... can only be used wrt to the context node
 			i think the easiest thing to think about is just iterating through these state nodes in a for-each
 			fashion. but... yah, can't do that in the top-down recursive manner that we're doing.
 
 		-->
+	
+		<xsl:variable name="stateNum">
+			<xsl:number level="any" count="s:state | s:parallel | s:final | s:initial | s:history"/>
+		</xsl:variable>
+
+		<!--
+		<xsl:message>
+			stateId: <xsl:value-of select="@id"/>
+			stateNum: <xsl:value-of select="$stateNum"/>
+		</xsl:message>
+		-->
 		
 		<xsl:copy>
 			<xsl:apply-templates select="@*"/>
@@ -51,31 +44,17 @@
 				the way I'm doing it now takes an O(n) operation and makes it into an O(n^2) op. really bad)
 				but it's not clear how else to get the position of a given node out of a node list...
 			-->
-			<xsl:for-each select="$states">
-				<xsl:if test="@id = $stateId">
 
-					<!--
-					<xsl:message>
-						stateid : <xsl:value-of select="$stateId"/>
-						stateNum : <xsl:number select="position()"/>
-					</xsl:message>
-					-->
-
-					<xsl:attribute name="stateNum" namespace="http://msdl.cs.mcgill.ca/">
-						<xsl:value-of select="position()"/>
-					</xsl:attribute>
-				</xsl:if>
-			</xsl:for-each>
+			<xsl:attribute name="stateNum" namespace="http://msdl.cs.mcgill.ca/">
+				<xsl:value-of select="$stateNum"/>
+			</xsl:attribute>
 
 			<xsl:apply-templates select="node()"/>
 		</xsl:copy>
 	</xsl:template>
 
-	<xsl:template match="s:transition">
 
-		<xsl:variable name="tName">
-			<xsl:value-of select="@c:tName"/>
-		</xsl:variable>
+	<xsl:template match="s:transition">
 
 		<!-- what we want to ask is, what is his position in the nodeset that we've constructed? 
 			but we can't use position normally... can only be used wrt to the context node
@@ -83,6 +62,17 @@
 			fashion. but... yah, can't do that in the top-down recursive manner that we're doing.
 
 		-->
+	
+		<xsl:variable name="transitionNum">
+			<xsl:number level="any" count="s:transition"/>
+		</xsl:variable>
+
+		<!--
+		<xsl:message>
+			tName: <xsl:value-of select="@c:tName"/>
+			transitionNum: <xsl:value-of select="$transitionNum"/>
+		</xsl:message>
+		-->
 		
 		<xsl:copy>
 			<xsl:apply-templates select="@*"/>
@@ -93,20 +83,13 @@
 				the way I'm doing it now takes an O(n) operation and makes it into an O(n^2) op. really bad)
 				but it's not clear how else to get the position of a given node out of a node list...
 			-->
-			<xsl:for-each select="$transitions">
-				<xsl:if test="@c:tName = $tName">
 
-					<xsl:attribute name="tNum" namespace="http://msdl.cs.mcgill.ca/">
-						<xsl:value-of select="position()"/>
-					</xsl:attribute>
-				</xsl:if>
-			</xsl:for-each>
+			<xsl:attribute name="tNum" namespace="http://msdl.cs.mcgill.ca/">
+				<xsl:value-of select="$transitionNum"/>
+			</xsl:attribute>
 
 			<xsl:apply-templates select="node()"/>
 		</xsl:copy>
 	</xsl:template>
 
 </xsl:stylesheet>
-
-
-