Created
August 23, 2009 05:04
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>&\textbf{</xsl:text><xsl:value-of select="."/><xsl:text>}</xsl:text> | |
</xsl:for-each> | |
<xsl:text>&\$</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>&</xsl:text><xsl:value-of select="$transitionsForNode[b:label/b:monElmt/b:monGen/@value = $thisColumn]/@target"/> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:text>&reject</xsl:text> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:for-each> | |
<xsl:choose> | |
<xsl:when test="../../b:transitions/b:final[@state = $nodeId]"> | |
<xsl:text>&accept</xsl:text> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:text>&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