commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbe...@apache.org
Subject svn commit: r954079 - /commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/computeLCA.xsl
Date Sat, 12 Jun 2010 19:37:30 GMT
Author: jbeard
Date: Sat Jun 12 19:37:30 2010
New Revision: 954079

URL: http://svn.apache.org/viewvc?rev=954079&view=rev
Log:
Intermediate commit. Working on LCA.

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

Added: 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=954079&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/computeLCA.xsl (added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/computeLCA.xsl Sat Jun 12 19:37:30
2010
@@ -0,0 +1,111 @@
+<?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>
+
+	<!--
+	//augment our AST to allow easy retrieval of enter and exit states from transitions
+	util.foreach(conf.transitions,function(t){
+
+		var startnode = t.parent();
+		var exitpath, lca;
+
+		util.foreach(t.msdl::targets.msdl::target,function(targetNode){
+
+			var endnode = conf.allStates.(@id == targetNode.msdl::targetState.text());
+
+			var enterpath;
+			[enterpath, exitpath, lca] = getTransitionPath(conf.allStates,startnode,endnode);
+
+			if(enterpath){
+				enterpath.forEach(function(state){
+					targetNode.msdl::enterpath.msdl::state += state.@id;
+				});
+			}
+			
+		});
+
+		if(exitpath){
+			exitpath.forEach(function(state){
+				t.msdl::exitpath.msdl::state += state.@id;
+			});
+		}
+
+		if(lca){
+			t.msdl::lca = lca.@id;
+		}
+
+	});
+	-->
+
+	<xsl:template name="genStateTree">
+		<xsl:param name="current"/>
+		<xsl:param name="end"/>
+
+		<xsl:variable name="parent" select="parent::$current"/>
+
+		<c:state>
+			<xsl:value-of select="$parent/@id"/>
+		</c:state>
+
+		<xsl:if test="not(current=end)">
+			<xsl:call-template name="genStateTree">
+				<xsl:with-param name="current" select="$parent"/>
+				<xsl:with-param name="end" select="$end"/>
+			</xsl:call-template>
+		</xsl:if>
+	</xsl:template>
+
+	<xsl:template match="s:transition">
+
+		<xsl:variable name="srcState" select="parent::."/>
+
+		<xsl:for-each select="./c:targets/c:target">
+			<!-- get the target state -->
+			<xsl:variable name="targetId" select="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]"/>
+
+			<!-- 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:copy>
+				<c:enterpath>
+					<xsl:call-template name="genStateTree">
+						<xsl:with-param name="current" select="$srcState"/>
+						<xsl:with-param name="end" select="$lca"/>
+					</xsl:apply-template>
+				</c:enterpath>
+				<c:exitpath>
+					<xsl:call-template name="genStateTree">
+						<xsl:with-param name="current" select="$targetState"/>
+						<xsl:with-param name="end" select="$lca"/>
+					</xsl:apply-template>
+				</c:exitpath>
+				<c:lca>
+					<xsl:value-of select="$lca/@id"/>
+				</c:lca>
+			</xsl:copy>
+
+		</xsl:for-each>
+
+
+	</xsl:template>
+
+</xsl:stylesheet>
+
+
+
+
+

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



Mime
View raw message