commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbe...@apache.org
Subject svn commit: r954095 - in /commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt: flattenTransitions.xsl nameTransitions.xsl numberStatesAndTransitions.xsl
Date Sat, 12 Jun 2010 19:39:30 GMT
Author: jbeard
Date: Sat Jun 12 19:39:29 2010
New Revision: 954095

URL: http://svn.apache.org/viewvc?rev=954095&view=rev
Log:
Added three new xsl transforms for transforming enumerated statecharts. Now to test and see
if they work.

Added:
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/flattenTransitions.xsl   (with props)
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/nameTransitions.xsl   (with props)
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/numberStatesAndTransitions.xsl   (with
props)

Added: commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/flattenTransitions.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/flattenTransitions.xsl?rev=954095&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/flattenTransitions.xsl (added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/flattenTransitions.xsl Sat Jun 12 19:39:29
2010
@@ -0,0 +1,122 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
+	xmlns:s="http://www.w3.org/2005/07/scxml"
+	xmlns="http://www.w3.org/2005/07/scxml"
+	xmlns:c="http://msdl.cs.mcgill.ca/"
+	version="1.0">
+	<xsl:output method="xml"/>
+
+	<!-- identity transform -->
+	<xsl:template match="@*|node()">
+		<xsl:copy>
+			<xsl:apply-templates select="@*|node()"/>
+		</xsl:copy>
+	</xsl:template>
+
+	<!--
+	var origin = t.parent();
+	if(!conf.basicStates.contains(origin)){
+		//for each basic state, if the state does not have a transition with the same event, copy
the transition into him
+		util.foreach(origin..state,function(d){
+			if(conf.basicStates.contains(d) && !d.transition.@event.contains(t.@event)){
+				d.transition += t.copy();
+			}
+		});
+
+		//delete the transition off of the composite state
+		delete origin.children()[t.childIndex()];
+	}
+	-->
+	<!--
+		if the origin is non-basic
+			for each of the origin's substates
+				if the substate is nonbasic and the substate is not the origin for any transitions that
have the same event as the origin transition
+					then copy the original transition as a child of the substate
+
+		for each non-basic state
+			for each transition where he is the origin
+				for each of his descendant basic states
+					if the descendant basic state does not already have a transition where he is the origin
that has the same event as the original transition
+						then copy the original transition as a child of the basic state
+
+		also, if we hit another composite state that has a transition with the same event, then
that one taks priority. That will make it work.
+	-->
+
+	<xsl:template name="getActiveTransitions">
+		<xsl:param name="parentTransitions"/>
+		<xsl:param name="currentTransitions"/>
+
+		<xsl:variable name="filteredParentTransitions"> 
+			<xsl:for-each select="$parentTransitions">
+				<xsl:variable name="parentTransitionEvent" select="@event"/>
+
+				<xsl:if test="not($currentTransitions[@event = $parentTransitionEvent])">
+					<xsl:copy-of select="."/>
+				</xsl:if>
+			</xsl:for-each>
+		</xsl:variable>
+
+		<xsl:copy-of select="$filteredParentTransitions | $currentTransitions"/>
+
+	</xsl:template>
+
+
+	<!-- basic states -->
+	<xsl:template match="*[(self::s:state or self::s:parallel) and
+				not(.//*[(self::s:state or self::s:parallel or self::s:final or self::s:initial or self::s:history)])]
 
+				| s:final | self::s:initial | self::s:history">
+
+		<xsl:param name="parentTransitions"/>	
+
+		<xsl:variable name="currentTransitions" select="s:transition"/>
+
+		<xsl:variable name="activeTransitions">
+			<xsl:call-template name="getActiveTransitions">
+				<xsl:with-param name="parentTransitions" select="$parentTransitions"/>
+				<xsl:with-param name="currentTransitions" select="$currentTransitions"/>
+			</xsl:call-template>
+		</xsl:variable>
+
+		<xsl:copy>
+			<xsl:apply-templates select="@*"/>
+
+			<!-- replace all of his transitions with the set of active transitions, which have
been carried down from the root -->
+			<xsl:copy-of select="$activeTransitions"/>
+		
+			<xsl:apply-templates select="node()[not(self::s:transition)]"/>
+		</xsl:copy>
+	</xsl:template>
+
+	<!-- non-basic states -->
+	<xsl:template match="s:scxml | 
+				*[(self::s:state or self::s:parallel) and
+					.//*[(self::s:state or self::s:parallel or self::s:final or self::s:initial or self::s:history)]]">
+
+		<xsl:param name="parentTransitions"/>	
+
+		<!-- TODO: merge parent transitions with his own transitions -->
+
+		<xsl:variable name="currentTransitions" select="s:transition"/>
+
+		<xsl:variable name="activeTransitions">
+			<xsl:call-template name="getActiveTransitions">
+				<xsl:with-param name="parentTransitions" select="$parentTransitions"/>
+				<xsl:with-param name="currentTransitions" select="$currentTransitions"/>
+			</xsl:call-template>
+		</xsl:variable>
+
+		<xsl:copy>
+			<xsl:apply-templates select="@*"/>
+
+			<xsl:apply-templates select="s:state | s:parallel | s:final | s:initial | s:history">
+				<xsl:with-param name="parentTransitions" select="$activeTransitions"/> 
+			</xsl:apply-templates>
+		
+			<xsl:apply-templates select="node()[not self::s:state or self::s:parallel or self::s:final
or self::s:initial or self::s:history]"/>
+		</xsl:copy>
+	</xsl:template>
+
+
+</xsl:stylesheet>
+
+

Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/flattenTransitions.xsl
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/nameTransitions.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/nameTransitions.xsl?rev=954095&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/nameTransitions.xsl (added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/nameTransitions.xsl Sat Jun 12 19:39:29
2010
@@ -0,0 +1,42 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
+	xmlns:s="http://www.w3.org/2005/07/scxml"
+	xmlns="http://www.w3.org/2005/07/scxml"
+	xmlns:c="http://msdl.cs.mcgill.ca/"
+	version="1.0">
+	<xsl:output method="xml"/>
+
+	<!-- identity transform -->
+	<xsl:template match="@*|node()">
+		<xsl:copy>
+			<xsl:apply-templates select="@*|node()"/>
+		</xsl:copy>
+	</xsl:template>
+
+	<xsl:template match="s:transition">
+
+		<xsl:variable name="eventName">
+			<xsl:choose>
+				<xsl:when test="@event">
+					<xsl:value-of select="@event"/>
+				</xsl:when>
+				<xsl:otherwise>
+					<xsl:value-of select="'$default'"/>
+				</xsl:otherwise>
+			</xsl:choose>
+		</xsl:variable>
+	
+		<xsl:copy>
+			<xsl:apply-templates select="@*"/>
+
+			<xsl:attribute name="tName" namespace="http://msdl.cs.mcgill.ca/">
+				<xsl:value-of select="concat(../@id,'_',$eventName)"/>
+			</xsl:attribute>
+
+			<xsl:apply-templates select="node()"/>
+		</xsl:copy>
+	</xsl:template>
+
+
+</xsl:stylesheet>
+

Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/nameTransitions.xsl
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=954095&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/numberStatesAndTransitions.xsl (added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/numberStatesAndTransitions.xsl Sat
Jun 12 19:39:29 2010
@@ -0,0 +1,64 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
+	xmlns:s="http://www.w3.org/2005/07/scxml"
+	xmlns="http://www.w3.org/2005/07/scxml"
+	xmlns:c="http://msdl.cs.mcgill.ca/"
+	version="1.0">
+	<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>
+
+	<!-- identity transform -->
+	<xsl:template match="@*|node()">
+		<xsl:copy>
+			<xsl:apply-templates select="@*|node()"/>
+		</xsl:copy>
+	</xsl:template>
+
+	<xsl:template match="s:state | s:parallel | s:final | s:initial | s:history">
+
+		<xsl:variable name="stateId" select="@id"/>
+
+		<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>
+
+			<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>
+
+
+

Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/numberStatesAndTransitions.xsl
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message