<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="/pool/xslt_ht.xslt" type="application/xml"?>
<xsl:stylesheet
  xmlns = "http://www.w3.org/1999/xhtml"
  xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
  xmlns:dd = "http://herbaer.de/xmlns/20201201/dbdump"
  xmlns:d = "http://herbaer.de/xmlns/20051201/doc"
  xmlns:xl = "http://www.w3.org/1999/xlink"
  version = "1.0"
  exclude-result-prefixes = "d dd xl"
>
<!--
  Datenbank-Struktur als HTML
  2020-12-12 Herbert Schiemann <h.schiemann@herbaer.de>
  Borkener Str. 167, 46284 Dorsten, Deutschland
  GPL Version 2 oder neuer
  Jede Gewährleistung ist ausgeschlossen.
-->
<d:info xmlns="http://herbaer.de/xmlns/20051201/doc">
  <title>dump_struct_ht.xslt</title>
  <subtitle>Datenbank-Struktur als HTML</subtitle>
  <date>2020-12-12</date>
  <author>
    <personname>
      <firstname>Herbert</firstname>
      <surname>Schiemann</surname>
    </personname>
    <email>h.schiemann@herbaer.de</email>
  </author>
</d:info>

<xsl:output method="xml" encoding="utf-8" indent="yes"/>

<d:para role="stylesheet">
Das Skript <d:filename>dbdump</d:filename> benutzt diese Datei nicht.
</d:para>

<d:para>
Pfade relativ zur Stylesheet-Datei
</d:para>
<xsl:include href="/pool/path.xslt"/>

<d:para>Wurzel</d:para>
<xsl:template match="/">
  <xsl:variable name="title">
    <xsl:text>Datenbank </xsl:text>
    <xsl:value-of select="dd:dbdump/dd:dbname"/>
  </xsl:variable>
  <html>
    <head>
      <title><xsl:value-of select="$title"/></title>
      <link rel="stylesheet">
        <xsl:attribute name="href">
          <xsl:call-template name="path.stylepath">
            <xsl:with-param name="pth">../../../pool/folding.css</xsl:with-param>
          </xsl:call-template>
        </xsl:attribute>
      </link>
      <style>
thead       {font-weight: bold; }
thead tr td {cursor: pointer;   }
td + td     {padding-left: 1em; }
td.number   {text-align: right; }
      </style>
      <script>
        <xsl:attribute name="src">
          <xsl:call-template name="path.stylepath">
            <xsl:with-param name="pth">../../../pool/folding.js</xsl:with-param>
          </xsl:call-template>
        </xsl:attribute>
      </script>
      <script>
onload = function() {
  var f = new Folder();
  f.apply_to_doc_parent_child (document, "div",   "h2");
  f.apply_to_doc_parent_child (document, "tbody", "tr");
};
      </script>
      <style>
tr:first-child          {
  background-color: #dddddd ;
  cursor: n-resize ;
}
tbody.collapsed tr:first-child { cursor: s-resize ; }
tbody.collapsed tr + tr        { display: none; }
      </style>
    </head>
    <body>
      <h1><xsl:value-of select="$title"/></h1>
      <xsl:apply-templates/>
    </body>
  </html>
</xsl:template>

<d:para>Datenbank-Struktur</d:para>
<xsl:template match="dd:dbdump">
  <xsl:if test="dd:table">
    <div>
      <h2>Struktur</h2>
      <table>
        <xsl:apply-templates select="dd:table"/>
      </table>
    </div>
  </xsl:if>
</xsl:template>

<d:para>Struktur einer Tabelle</d:para>
<xsl:template match="dd:table">
  <xsl:variable name="name" select="dd:tabname"/>
  <tbody id="tab_{$name}">
    <xsl:apply-templates select="dd:field">
      <xsl:with-param name="tnam" select="$name"/>
    </xsl:apply-templates>
  </tbody>
</xsl:template>

<d:para>Ein Datenbank-Feld</d:para>
<xsl:template match="dd:field">
  <!-- Tabellenname -->
  <xsl:param name="tnam"/>
  <tr id="fld_{$tnam}.{dd:name}">
    <td>
      <xsl:if test="position() = 1">
        <xsl:value-of select="$tnam"/>
      </xsl:if>
    </td>
    <td>
      <xsl:value-of select="dd:name"/>
    </td>
    <td>
      <xsl:value-of select="dd:type"/>
    </td>
    <td>
      <xsl:if test="not(dd:null)">not null</xsl:if>
    </td>
    <td>
      <xsl:choose>
        <xsl:when test="dd:key = 'p'">primary</xsl:when>
        <xsl:when test="dd:key = 'u'">unique</xsl:when>
        <xsl:when test="dd:key = 'm'">index</xsl:when>
        <xsl:when test="string-length(dd:default) &gt; 0">
          <xsl:text>Default: </xsl:text>
          <xsl:value-of select="dd:default"/>
        </xsl:when>
        <xsl:otherwise/>
      </xsl:choose>
    </td>
  </tr>
</xsl:template>

</xsl:stylesheet>
