<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">
    <xsl:param name="homesym" select="&#34;&#160;||&#160;&#34;"/>
    <xsl:param name="leftsym" select="&#34;&#160;&gt;&gt;&#160;&#34;"/>
    <xsl:param name="rightsym" select="&#34;&#160;&lt;&lt;&#160;&#34;"/>
    <xsl:variable name="nactors">
        <xsl:value-of select="count(//cast/actor)"/>
    </xsl:variable>
    <xsl:variable name="width" select="100 div $nactors"/>
    <xsl:template match="/SequenceDiagram">
        <table border="1">
            <tr>
                <xsl:for-each select="//cast/actor">
                    <th width="{$width}%" bgcolor="{@color}">
                        <xsl:value-of select="@name"/>
                    </th>
                </xsl:for-each>
            </tr>
            <xsl:apply-templates select="trace/*"/>
        </table>
    </xsl:template>
    <xsl:template match="action">
        <xsl:variable name="at">
            <xsl:value-of select="@at"/>
        </xsl:variable>
        <xsl:variable name="do">
            <xsl:value-of select="@do"/>
        </xsl:variable>
        <tr>
            <xsl:for-each select="//cast/actor">
                <xsl:choose>
                    <xsl:when test="$at = @name ">
                        <td bgcolor="{//cast/actor[@name = $at]/@color}">
                            <xsl:value-of select="$do"/>
                        </td>
                    </xsl:when>
                    <xsl:otherwise>
                        <td/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:for-each>
        </tr>
    </xsl:template>
    <xsl:template match="message">
        <xsl:variable name="start">
            <xsl:value-of select="@from"/>
        </xsl:variable>
        <xsl:variable name="color">
            <xsl:value-of select="//cast/actor[@name=$start]/@color"/>
        </xsl:variable>
        <xsl:variable name="from">
            <xsl:value-of select="index-of(//cast/actor/@name,@from)"/>
        </xsl:variable>
        <xsl:variable name="to">
            <xsl:value-of select="index-of(//cast/actor/@name,@to)"/>
        </xsl:variable>
        <xsl:variable name="first">
            <xsl:value-of select="min(($from,$to))"/>
        </xsl:variable>
        <xsl:variable name="last">
            <xsl:value-of select="max(($from,$to))"/>
        </xsl:variable>
        <xsl:variable name="sym">
            <xsl:choose>
                <xsl:when test="$first = $from">
                    <xsl:value-of select="$leftsym"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$rightsym"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="text">
            <xsl:value-of select="concat($sym,@text,$sym)"/>
        </xsl:variable>
        <tr>
            <xsl:for-each select="(1 to xs:integer($first) - 1)">
                <td/>
            </xsl:for-each>
            <td align="center" colspan="{$last - $first + 1}" bgcolor="{$color}">
                <xsl:value-of select="$text"/>
            </td>
            <xsl:for-each select="(xs:integer($last) + 1  to xs:integer($nactors))">
                <td/>
            </xsl:for-each>
        </tr>
    </xsl:template>
</xsl:stylesheet>