<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) Daniel Sheffield 2022
All rights reserved.
-->
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.w3.org/1999/xhtml"
>

  <xsl:output method="xml"
      doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
      doctype-public="-//W3C/DTD XHTML 1.0 Strict//EN"
      indent="yes"/>

  <xsl:template match="/*">
    <xsl:variable name="schema" select="//xsd:schema"/>
    <xsl:variable name="tabletypename"
                  select="$schema/xsd:element[@name=name(current())]/@type"/>
    <xsl:variable name="rowtypename"
                  select="$schema/xsd:complexType[@name=$tabletypename]/xsd:sequence/xsd:element[@name='row']/@type"/>

    <html>
      <head>
	      <meta name="viewport" content="width=device-width, initial-scale=1"/>
	      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/purecss@2.1.0/build/pure-min.css" integrity="sha384-yHIFVG6ClnONEA5yB5DJXfW2/KC173DIQrYoZMEtBvGzmf0PKiGyNEqe9N6BNDBH" crossorigin="anonymous"/>
	      <link rel="stylesheet" href="https://shandan.one/css/grids-responsive-min.css"/>
	      <link rel="stylesheet" href="https://shandan.one/css/responsive-visibility-collapse.css"/>
        <title><xsl:value-of select="name(current())"/></title>
      </head>
      <body>
        <div style="background: darkgray; position: sticky; top: 0; margin: 0; padding: 0; width: 100%; z-index: 1; text-align: center;">
        <form action="random">
          <button type="submit" style="margin: 0.2em">Generate</button>
	</form>
        </div>
        <div style="position: relative; max-width: 68em; min-width: min(100%, 68em); left: 50%; transform: translate(max(-50%, -34em),0)">
        <table class="pure-table pure-table-bordered pure-table-striped">
          <tr style="text-transform: capitalize">
            <xsl:for-each select="$schema/xsd:complexType[@name=$rowtypename]/xsd:sequence/xsd:element/@name">
                <xsl:variable name="elementtype"
                              select="."/>
                <xsl:choose>
                <xsl:when test="$elementtype = 'txt'">
              <th class="opt-all">Text</th>
                </xsl:when>
                <xsl:when test="$elementtype = 'category'">
              <th class="opt-all">Section</th>
                </xsl:when>
                <xsl:when test="$elementtype = 'translation'">
              <th class="opt-md opt-lg opt-xl opt-xxl">Reference</th>
                </xsl:when>
                <xsl:otherwise>
                </xsl:otherwise>
                </xsl:choose>
            </xsl:for-each>
          </tr>

          <xsl:for-each select="row">
            <tr>
              <xsl:for-each select="*">
                <xsl:variable name="elementtype"
                              select="name(current())"/>
                <xsl:choose>
                <xsl:when test="$elementtype = 'txt'">
                <td class="opt-all"><xsl:value-of select="."/></td>
                </xsl:when>
                <xsl:when test="$elementtype = 'category'">
                  <xsl:choose>
                  <xsl:when test="contains(.,'z_')">
                  <td class="opt-all" rowspan="2" style="text-transform: capitalize;">Kingdom</td>
                  </xsl:when>
                  <xsl:when test="contains(.,'a_')">
                  </xsl:when>
		  <xsl:otherwise>
                  <td class="opt-all" style="text-transform: capitalize;"><xsl:value-of select="."/></td>
                  </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:when test="$elementtype = 'translation'">
                </xsl:when>
                <xsl:otherwise>
                  <td class="opt-md opt-lg opt-xl opt-xxl">
                  <xsl:value-of select="translate(translate(.,' ','&#160;'),'-','&#8209;')"/>
                  <br/>
                  <a>
                  <xsl:attribute name="href">/license/<xsl:value-of select="preceding-sibling::translation"/>.txt</xsl:attribute>
                  <xsl:value-of select="preceding-sibling::translation"/>
                  </a>
                  </td>
                </xsl:otherwise>
                </xsl:choose>
              </xsl:for-each>
            </tr>
          </xsl:for-each>
        <tfoot>
        <tr>
          <td colspan="3">Quotes are taken from various translations as indicated. See 
          <xsl:for-each select="//row/translation[not(.=preceding::*)]">
          <a>
          <xsl:attribute name="href">/license/<xsl:value-of select="."/>.txt</xsl:attribute>
          <xsl:value-of select="."/>
          </a>,
          </xsl:for-each>
          for the license of each respective work.
          </td>
        </tr>
        </tfoot>
        </table>
        </div>
      </body>
    </html>
  </xsl:template>

</xsl:stylesheet>
