Author: jbeard
Date: Thu Mar 17 16:19:06 2011
New Revision: 1082564

URL: http://svn.apache.org/viewvc?rev=1082564&view=rev
Log:
Added support for commands in generated output.

Modified:
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/util/scxml-to-dot.xsl

Modified: 
commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/util/scxml-to-dot.xsl
URL: 
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/util/scxml-to-dot.xsl?rev=1082564&r1=1082563&r2=1082564&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/util/scxml-to-dot.xsl 
(original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/util/scxml-to-dot.xsl Thu 
Mar 17 16:19:06 2011
@@ -27,11 +27,29 @@ a document in the graphviz dot syntax.
        <import href="xml-to-string.xsl"/>
        <output method="text"/>
 
+       <variable name="states" select="//s:state | //s:parallel"/>
+
        <template match="/">
                digraph G {
                        <apply-templates select="*[not(self::s:transition)]"/>
 
-                       <apply-templates select="//s:transition[@target]"/>
+                       <for-each select="$states">
+                               <variable name="fromState" select="."/>
+
+                               <for-each select="$states">
+                                       <variable name="toState" select="."/>
+                                       
+                                       <variable name="transitions" 
select="$fromState/s:transition[@target=$toState/@id]"/>
+
+                                       <if test="$transitions">
+                                               <call-template 
name="transition-template">
+                                                       <with-param 
name="transitions" select="$transitions"/>
+                                                       <with-param 
name="sourceState" select="$fromState"/>
+                                                       <with-param 
name="targetState" select="$toState"/>
+                                               </call-template>
+                                       </if>
+                               </for-each>
+                       </for-each>
                }
        </template>
 
@@ -54,9 +72,12 @@ a document in the graphviz dot syntax.
                <value-of select="@id"/>;
        </template>
 
-       <template match="s:transition[@target]">
-               <variable name="sourceId" select="../@id"/>
-               <variable name="sourceState" select="//*[@id=$sourceId]"/>
+       <template name="transition-template">
+               <param name="transitions"/>
+               <param name="sourceState"/>
+               <param name="targetState"/>
+
+               <variable name="sourceId" select="$sourceState/@id"/>
                <variable name="sourceStatesBasicSubstates" 
select="$sourceState//s:state[not(.//s:state)]"/>
 
                <variable name="sourceBasicStateId">
@@ -73,8 +94,7 @@ a document in the graphviz dot syntax.
                </variable>
 
 
-               <variable name="targetId" select="@target"/>
-               <variable name="targetState" select="//*[@id=$targetId]"/>
+               <variable name="targetId" select="$targetState/@id"/>
                <variable name="targetStatesBasicSubstates" 
select="$targetState//s:state[not(.//s:state)]"/>
 
                <variable name="targetBasicStateId">
@@ -100,9 +120,35 @@ a document in the graphviz dot syntax.
                        <if test="$targetStatesBasicSubstates">
                                lhead=cluster_<value-of select="$targetId"/>,
                        </if>
-                       <if test="@event | s:script | @cond">
-                               label="<value-of select="@event"/><if 
test="@cond">[<value-of select="@cond"/>]</if>"
-                       </if>
+                       <choose>
+                               <when test="count($transitions) > 1">
+                                       <!-- multiple transitions. use html 
label -->
+                                       <!-- FIXME: this code is ugly and 
repeated twice -->
+                                       label=&lt;&lt;TABLE&gt;<for-each 
select="$transitions">&lt;TR&gt;&lt;TD&gt;<value-of 
select="@event"/>&lt;/TD&gt;&lt;TD&gt;<call-template 
name="attribute-value"><with-param name="text" 
select="@cond"/></call-template>&lt;/TD&gt;&lt;/TR&gt;</for-each>&lt;/TABLE&gt;&gt;
+                               </when>
+                               <otherwise>
+                                       <variable name="firstTransition" 
select="$transitions[1]"/>
+
+                                       <if test="$firstTransition/@event | 
$firstTransition/s:script | $firstTransition/@cond">
+                                               <text>label="</text> 
+                                               <value-of 
select="$firstTransition/@event"/> 
+                                               <if 
test="$firstTransition/@cond"> 
+                                                       <text>[</text>
+                                                       <value-of 
select="$firstTransition/@cond"/>
+                                                       <text>]</text> 
+                                               </if> 
+                                               <if 
test="$firstTransition/s:script"> 
+                                                       <text>/</text>
+                                                       <call-template 
name="replace-string"> 
+                                                               <with-param 
name="text" select="$firstTransition/s:script"/> 
+                                                               <with-param 
name="replace" select="'&#10;'"/> 
+                                                               <with-param 
name="with" select="'\n'"/> 
+                                                       </call-template> 
+                                               </if>
+                                               <text>"</text>
+                                       </if>
+                               </otherwise>
+                       </choose>
                ];
        </template>
 


Reply via email to