<?xml version="1.0" ?>
<xsl:transform version = '1.0'
  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
  xmlns="http://www.w3.org/1999/xhtml">

<xsl:template match="/bytecode">
  <html>
    <head>
      <title>Python bytecode</title>
      <link rel="stylesheet" type="text/css" href="bytecode.css"/>
    </head>
    <body>
      <h2>Python bytecode</h2>
      <p>
        <xsl:apply-templates select="head"/>
      </p>
      <p>
        <xsl:apply-templates select="code"/>
      </p>
    </body>
  </html>
</xsl:template>

<xsl:template match="head">
  Magic: <xsl:value-of select="magic"/> <br />
  Modtime: <xsl:value-of select="modtime"/>
</xsl:template>

<xsl:template match="code">
  <div>
    code:
    <ul type="square">
      <li>
        Name: '<xsl:value-of select="co_name"/>'
        <span style="margin-left: 3em;">
          <xsl:value-of select="co_filename"/><xsl:text>:</xsl:text>
          <xsl:value-of select="co_firstlineno"/>
        </span>
      </li>
      <li>
        <pre><xsl:value-of select="co_code"/></pre>
      </li>
      <!--      <li>
        Varnames: <xsl:apply-templates select="co_varnames"/>
      </li>  -->
      <li>
        Names: <xsl:apply-templates select="co_names"/>
      </li>
      <li>
        Consts:
        <xsl:apply-templates select="co_consts"/>
      </li>
    </ul>
  </div>
</xsl:template>

<xsl:template match="co_names">
  <xsl:for-each select="item">
    <xsl:value-of select="."/>
    <xsl:if test="position() != last()">
      <xsl:text>, </xsl:text>
    </xsl:if>
  </xsl:for-each>
</xsl:template>

<xsl:template match="co_consts">
  <ol start="0">
    <xsl:for-each select="(item|code)">
      <xsl:if test="name(.) = 'item'">
        <li>
          <xsl:value-of select="."/>
        </li>
      </xsl:if>
      <xsl:if test="name(.) = 'code'">
        <li>
          <xsl:apply-templates select="."/>
        </li>
      </xsl:if>
    </xsl:for-each>
  </ol>
</xsl:template>

</xsl:transform>
