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:36 UTC
svn commit: r954096 -
/commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/numberStatesAndTransitions.xsl
Author: jbeard
Date: Sat Jun 12 19:39:35 2010
New Revision: 954096
URL: http://svn.apache.org/viewvc?rev=954096&view=rev
Log:
Found a way to make countStatesAndTransitions.xsl work, but not too happy with it, so this is something I'm going to iterate on.
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=954096&r1=954095&r2=954096&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:35 2010
@@ -7,13 +7,18 @@
<xsl:output method="xml"/>
<!-- we copy them, so that we can use their positions as identifiers -->
- <xsl:variable name="states">
- <xsl:copy-of select="//*[self::s:state or self::s:parallel or self::s:final or self::s:initial or self::s:history]"/>
- </xsl:variable>
-
- <xsl:variable name="transitions"/>
- <xsl:copy-of select="s:transition"/>
- </xsl:variable>
+ <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: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()">
@@ -24,39 +29,44 @@
<xsl:template match="s:state | s:parallel | s:final | s:initial | s:history">
- <xsl:variable name="stateId" select="@id"/>
+ <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:copy>
<xsl:apply-templates select="@*"/>
<!-- FIXME: subtract 1 for 0-based indexing in generated code?
No, we probably want to adjust this in the code generator-->
- <xsl:attribute name="stateNum" namespace="http://msdl.cs.mcgill.ca/">
- <xsl:value-of select="position($states[@id = $stateId])"/>
- </xsl:attribute>
+ <!--FIXME: there has GOT to be a more efficient way to do this
+ 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:value-of 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:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
- <xsl:template match="s:transition">
-
- <!-- TODO: refactor tName to id to reflect the fact that it is being used as a unique identifier? -->
- <xsl:variable name="transitionName" select="@c:tName"/>
-
- <xsl:copy>
- <xsl:apply-templates select="@*"/>
-
- <!-- FIXME: subtract 1 for 0-based indexing in generated code?
- No, we probably want to adjust this in the code generator-->
- <xsl:attribute name="tNum" namespace="http://msdl.cs.mcgill.ca/">
- <xsl:value-of select="position($transitions[@c:tName = $transitionName])"/>
- </xsl:attribute>
-
- <xsl:apply-templates select="node()"/>
- </xsl:copy>
-
- </xsl:template>
</xsl:stylesheet>