Skip to content

Instantly share code, notes, and snippets.

@dMaggot
Created August 23, 2009 04:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dMaggot/173162 to your computer and use it in GitHub Desktop.
XSLT to transform an Automata description from FSMXML to Graphviz DOT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:b="http://vaucanson.lrde.epita.fr">
<xsl:output method="text" />
<xsl:template match="/">
<xsl:apply-templates select="b:fsmxml/b:automaton" />
</xsl:template>
<xsl:template match="b:automaton">
<xsl:text>digraph </xsl:text>
<xsl:value-of select="@name" />
<xsl:text> { rankdir=LR; </xsl:text>
<xsl:apply-templates select="b:automatonStruct" />
<xsl:text>}</xsl:text>
</xsl:template>
<xsl:template match="b:automatonStruct">
<xsl:text>node [shape=doublecircle]; </xsl:text>
<xsl:for-each select="b:transitions/b:final">
<xsl:value-of select="@state" />
<xsl:text> </xsl:text>
</xsl:for-each>
<xsl:text>; </xsl:text>
<xsl:text>node [shape=circle, style=invis]; _initial_;</xsl:text>
<xsl:text>node [style=solid]; </xsl:text>
<xsl:for-each select="b:transitions/b:initial">
<xsl:text>_initial_ -></xsl:text>
<xsl:value-of select="@state" />
<xsl:text>; </xsl:text>
</xsl:for-each>
<xsl:for-each select="b:transitions/b:transition">
<xsl:value-of select="@src" />
<xsl:text> -> </xsl:text>
<xsl:value-of select="@target" />
<xsl:text> </xsl:text>
<xsl:text> [label ="</xsl:text>
<xsl:value-of select="b:label/b:monElmt/b:monGen/@value" />
<xsl:text>"]; </xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment