Skip to content

Instantly share code, notes, and snippets.

@dMaggot
Created August 23, 2009 05:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dMaggot/173164 to your computer and use it in GitHub Desktop.
Save dMaggot/173164 to your computer and use it in GitHub Desktop.
XSLT to transform an Automata description from FSMXML to a LaTeX function matrix
<?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:variable name="columns" as="item()*">
<xsl:for-each select="b:valueType/b:monoid/b:monGen">
<xsl:value-of select="@value" />
</xsl:for-each>
</xsl:variable>
<xsl:text>\begin{tabular}{l|</xsl:text>
<xsl:for-each select="$columns">
<xsl:text>c|</xsl:text>
</xsl:for-each>
<xsl:text>c|}</xsl:text>
<xsl:for-each select="$columns">
<xsl:text>&amp;\textbf{</xsl:text><xsl:value-of select="."/><xsl:text>}</xsl:text>
</xsl:for-each>
<xsl:text>&amp;\$</xsl:text>
<xsl:apply-templates select="b:automatonStruct">
<xsl:with-param name="columns" select="$columns"/>
</xsl:apply-templates>
<xsl:text>\end{tabular}</xsl:text>
</xsl:template>
<xsl:template match="b:automatonStruct">
<xsl:param name="columns"/>
<xsl:for-each select="b:states/b:state">
<xsl:text>\\\hline </xsl:text>
<xsl:variable name="nodeId" select="@id"/>
<xsl:variable name="transitionsForNode" as="item()*">
<xsl:sequence select="../../b:transitions/b:transition[@src = $nodeId]"/>
</xsl:variable>
<xsl:text>\textbf{</xsl:text><xsl:value-of select="@id"/><xsl:text>}</xsl:text>
<xsl:for-each select="$columns">
<xsl:variable name="thisColumn" select="."/>
<xsl:choose>
<xsl:when test="$transitionsForNode[b:label/b:monElmt/b:monGen/@value = $thisColumn]">
<xsl:text>&amp;</xsl:text><xsl:value-of select="$transitionsForNode[b:label/b:monElmt/b:monGen/@value = $thisColumn]/@target"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>&amp;reject</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:choose>
<xsl:when test="../../b:transitions/b:final[@state = $nodeId]">
<xsl:text>&amp;accept</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>&amp;reject</xsl:text>
</xsl:otherwise>
</xsl:choose>
</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