<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output method="html"/>

   <xsl:template match="collection">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
         <title>dbXML Collection Listing: <xsl:value-of select="@path" /></title>
         <style type="text/css">
         form {
            margin: 0px;
         }
         td {
            text-align: left;
            vertical-align: top;
            background-position: left top;
         }
         .logo {
            font-family: Neuro, Neuropolitical, Arial, Helvetica, sans-serif;
            font-size: 14pt;
            color: #000000;
         }
         .logodb {
            font-family: Neuro, Neuropolitical, Arial, Helvetica, sans-serif;
            font-size: 14pt;
            color: #000000;
         }
         .logoxml {
            font-family: Neuro, Neuropolitical, Arial, Helvetica, sans-serif;
            font-size: 14pt;
            font-weight: bold;
            color: #0C024E;
         }
         .heading {
            font-family: Arial, Helvetica, sans-serif;
            font-size: 14pt;
            font-weight: bold;
         }
         .noheading {
            font-family: Arial, Helvetica, sans-serif;
            font-size: 14pt;
            color: gray
         }
         .listing {
            font-family: Arial, Helvetica, sans-serif;
            font-size: 12pt;
         }
         .nolisting {
            font-family: Arial, Helvetica, sans-serif;
            font-size: 12pt;
            color: gray
         }
         .doc {
            font-family: Arial, Helvetica, sans-serif;
            font-size: 10pt;
            float: left;
            width: 25%;
            //overflow: hidden;
         }
         .nodoc {
            font-family: Arial, Helvetica, sans-serif;
            font-size: 10pt;
            color: gray
         }
         </style>
      </head>
      <body>
      <table border="1" cellpadding="5" cellspacing="0">
         <tr bgcolor="#C8C8FF">
            <td colspan="5">
               <span class="logo">
                  &lt;<span class="logodb">db</span>
                  <span class="logoxml">XML</span>&gt;
               </span>
               <span class="heading"> Collection Listing: </span>
               <span class="listing"><xsl:value-of select="@path" /></span>
            </td>
         </tr>
         <tr>
            <td colspan="1" class="listing">
               <xsl:choose>
                  <xsl:when test="@path!='/'">
                     <a href="..">Up One Level</a>
                  </xsl:when>
                  <xsl:otherwise>
                     <span class="nolisting">Database Root</span>
                  </xsl:otherwise>
               </xsl:choose>
            </td>
            <td colspan="4" nowrap="nowrap" class="listing">
               <xsl:if test="/collection[@type='documents'] and count(/collection/documents/document)!=0">
                  <form action="." method="get">
                     <input type="hidden" name="method" value="queryCollection" />
                     <input type="hidden" name="style" value="XPath" />
                     XPath Query <input type="text" name="query" size="50" value="/*" />
                     <input type="submit" value="Query" />
                  </form>
               </xsl:if>
            </td>
         </tr>
         <tr bgcolor="#F0F0FF">
            <td width="20%" nowrap="nowrap" class="heading">Child Collections</td>
            <td width="20%" nowrap="nowrap" class="heading">Indexes</td>
            <td width="20%" nowrap="nowrap" class="heading">Extensions</td>
            <td width="20%" nowrap="nowrap" class="heading">Triggers</td>
            <td width="20%" nowrap="nowrap" class="heading">Permissions</td>
         </tr>
         <tr>
            <td nowrap="nowrap">
               <xsl:choose>
                  <xsl:when test="count(children/child)=0">
                     <span class="nolisting">No Collections</span>
                  </xsl:when>
                  <xsl:otherwise>
                     <span class="listing">
                        <xsl:apply-templates select="children/child" />
                     </span>
                  </xsl:otherwise>
               </xsl:choose>
            </td>
            <td nowrap="nowrap">
               <xsl:choose>
                  <xsl:when test="count(indexes/index)=0">
                     <span class="nolisting">No Indexes</span>
                  </xsl:when>
                  <xsl:otherwise>
                     <span class="listing">
                        <xsl:apply-templates select="indexes/index" />
                     </span>
                  </xsl:otherwise>
               </xsl:choose>
            </td>
            <td nowrap="nowrap">
               <xsl:choose>
                  <xsl:when test="count(extensions/extension)=0">
                     <span class="nolisting">No Extensions</span>
                  </xsl:when>
                  <xsl:otherwise>
                     <span class="listing">
                        <xsl:apply-templates select="extensions/extension" />
                     </span>
                  </xsl:otherwise>
               </xsl:choose>
            </td>
            <td nowrap="nowrap">
               <xsl:choose>
                  <xsl:when test="count(triggers/trigger)=0">
                     <span class="nolisting">No Triggers</span>
                  </xsl:when>
                  <xsl:otherwise>
                     <span class="listing">
                        <xsl:apply-templates select="triggers/trigger" />
                     </span>
                  </xsl:otherwise>
               </xsl:choose>
            </td>
            <td nowrap="nowrap">
               <xsl:choose>
                  <xsl:when test="count(roles/role)=0">
                     <span class="nolisting">No Roles</span>
                  </xsl:when>
                  <xsl:otherwise>
                     <span class="listing">
                        <xsl:apply-templates select="roles/role" />
                     </span>
                  </xsl:otherwise>
               </xsl:choose>
            </td>
         </tr>
         <tr bgcolor="#F0F0FF">
            <td colspan="5" nowrap="nowrap" class="heading">Documents</td>
         </tr>
         <tr>
            <td colspan="5">
               <xsl:choose>
                  <xsl:when test="count(documents/document)=0">
                     <span class="nodoc">No Documents</span>
                  </xsl:when>
                  <xsl:otherwise>
                     <span class="listing">
                        <xsl:choose>
                           <xsl:when test="/collection[@type='documents']">
                              <xsl:apply-templates select="documents/document" mode="documents"/>
                           </xsl:when>
                           <xsl:when test="/collection[@type='records']">
                              <xsl:apply-templates select="documents/document" mode="records"/>
                           </xsl:when>
                           <xsl:otherwise>
                              <xsl:apply-templates select="documents/document" mode="other"/>
                           </xsl:otherwise>
                        </xsl:choose>
                     </span>
                  </xsl:otherwise>
               </xsl:choose>
            </td>
         </tr>
      </table>
      </body>
      </html>
   </xsl:template>

   <xsl:template match="child">
      <a href="{.}/"><xsl:value-of select="." /></a><br />
   </xsl:template>

   <xsl:template match="index">
      <xsl:value-of select="." /><br />
   </xsl:template>

   <xsl:template match="extension">
      <xsl:value-of select="." /><br />
   </xsl:template>

   <xsl:template match="trigger">
      <xsl:value-of select="." /><br />
   </xsl:template>

   <xsl:template match="role">
      <xsl:value-of select="." /> (<xsl:value-of select="@permissions"/>)<br />
   </xsl:template>

   <xsl:template match="document" mode="documents">
      <xsl:choose>
         <xsl:when test="contains(., '/')">
            <div class="doc"><a href="?method=getDocument&amp;docKey={.}"><xsl:value-of select="." /></a></div>
         </xsl:when>
         <xsl:otherwise>
            <div class="doc"><a href="{.}"><xsl:value-of select="." /></a></div>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <xsl:template match="document" mode="records">
      <xsl:choose>
         <xsl:when test="contains(., '/')">
            <div class="doc"><a href="?method=getValue&amp;key={.}"><xsl:value-of select="." /></a></div>
         </xsl:when>
         <xsl:otherwise>
            <div class="doc"><a href="{.}"><xsl:value-of select="." /></a></div>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <xsl:template match="document" mode="other">
      <div class="doc"><a href="{.}"><xsl:value-of select="." /></a></div>
   </xsl:template>
</xsl:stylesheet>
