Edit online

How to Display Glossary as a Table

Suppose you want to display the content of your Glossary as a table, to condense the information for one entry on a single line.

Remember:
Make sure all the glossary is contained within a single <glossgroup> element.
To add this functionality, use an Oxygen Publishing Template and follow these steps:
  1. If you have not already created a Publishing Template, you need to create one. For details, see How to Create a Publishing Template.
  2. Link the folder associated with the publishing template to your current project in the Project view.
  3. Using the view, create an xslt folder inside the project root folder.
  4. In the newly created folder, create an XSL file (for example, named merged2html5Extension.xsl) with the following content:
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:dita2html="http://dita-ot.sourceforge.net/ns/200801/dita2html"
      exclude-result-prefixes="xs dita2html" version="3.0">
    
      <!-- Create a table that will contain all the glossentries contained in the glossgroup. -->
      <xsl:template name="gen-topic">
        <xsl:param name="nestlevel" as="xs:integer">
          <xsl:choose>
            <!-- Limit depth for historical reasons, could allow any depth. -->
            <!-- Previously limit was 5. -->
            <xsl:when
              test="count(ancestor::*[contains(@class, ' topic/topic ')]) > 9"
              >9</xsl:when>
            <xsl:otherwise>
              <xsl:sequence
                select="count(ancestor::*[contains(@class, ' topic/topic ')])"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:param>
        <xsl:choose>
          <xsl:when test="parent::dita and not(preceding-sibling::*)">
            <!-- Do not reset xml:lang if it is already set on <html> -->
            <!-- Moved outputclass to the body tag -->
            <!-- Keep ditaval based styling at this point -->
            <!-- (replace DITA-OT 1.6 and earlier call to gen-style) -->
            <xsl:apply-templates
              select="*[contains(@class, ' ditaot-d/ditaval-startprop ')]/@style"
              mode="add-ditaval-style"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="commonattributes">
              <xsl:with-param name="default-output-class"
                select="concat('nested', $nestlevel)"/>
            </xsl:call-template>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:call-template name="gen-toc-id"/>
        <xsl:call-template name="setidaname"/>
        <xsl:choose>
          <xsl:when test="contains(@class, 'glossgroup/glossgroup')">
            <!-- Custom processing for glossgroup. -->
            <xsl:apply-templates select="*[contains(@class, 'topic/title')]"/>
            <table class="- glossgroup/table table">
              <thead class="- glossgroup/thead thead">
                <tr class="- glossgroup/row row">
                  <th class="- glossgroup/entry entry">Acronym</th>
                  <th class="- glossgroup/entry entry">Term</th>
                  <th class="- glossgroup/entry entry">Full Term</th>
                  <xsl:if
                    test="exists(//*[contains(@class, 'glossentry/glossdef')])">
                    <th class="- glossgroup/entry entry">Definition</th>
                  </xsl:if>
                </tr>
              </thead>
              <xsl:apply-templates
                select="*[contains(@class, 'glossentry/glossentry')]"/>
            </table>
            <xsl:apply-templates select="
                * except (*[contains(@class, 'topic/title')]
                | *[contains(@class, 'glossentry/glossentry')])"/>
          </xsl:when>
          <xsl:otherwise>
            <!-- Default processing. -->
            <xsl:apply-templates/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:template>
    
      <!-- Create a row for each glossentry. -->
      <xsl:template
        match="*[contains(@class, 'glossentry/glossentry')]
        [parent::*[contains(@class, 'glossgroup/glossgroup')]]">
        <xsl:variable name="glossentry" as="node()">
          <xsl:next-match/>
        </xsl:variable>
        <tr>
          <xsl:copy-of select="$glossentry/@*"/>
          <xsl:copy-of
            select="$glossentry/*[contains(@class, 'glossentry/glossAlt')]"/>
          <xsl:copy-of
            select="$glossentry/*[contains(@class, 'glossentry/glossterm')]"/>
          <xsl:copy-of
            select="$glossentry/*[contains(@class, 'glossentry/glossSurfaceForm')]"/>
          <xsl:copy-of
            select="$glossentry/*[contains(@class, 'glossentry/glossdef')]"/>
          <xsl:copy-of select="
              $glossentry/* except $glossentry/*[contains(@class, 'glossentry/glossAlt')
              or contains(@class, 'glossentry/glossterm')
              or contains(@class, 'glossentry/glossSurfaceForm')
              or contains(@class, 'glossentry/glossdef')]"/>
        </tr>
      </xsl:template>
    
      <!-- Process only glossBody's children nodes. -->
      <xsl:template
        match="*[contains(@class, 'glossentry/glossBody')]
        [ancestor::*[contains(@class, 'glossgroup/glossgroup')]]">
        <xsl:apply-templates/>
      </xsl:template>
    
      <!-- Create a cell for each glossterm, glossSurfaceForm and glossAlt. -->
      <xsl:template match="
          *[contains(@class, 'glossentry/glossterm')]
          [ancestor::*[contains(@class, 'glossgroup/glossgroup')]] |
          *[contains(@class, 'glossentry/glossSurfaceForm')]
          [ancestor::*[contains(@class, 'glossgroup/glossgroup')]] |
          *[contains(@class, 'glossentry/glossAlt')]
          [ancestor::*[contains(@class, 'glossgroup/glossgroup')]]">
        <xsl:variable name="glossContent" as="node()">
          <xsl:next-match/>
        </xsl:variable>
        <td>
          <xsl:copy-of select="$glossContent/@*"/>
          <xsl:copy-of select="normalize-space(string-join($glossContent//text()))"
          />
        </td>
      </xsl:template>
    
      <!-- Create a cell for each glossdef. -->
      <xsl:template
        match="*[contains(@class, 'glossentry/glossdef')]
        [ancestor::*[contains(@class, 'glossgroup/glossgroup')]]">
        <td>
          <xsl:call-template name="commonattributes"/>
          <xsl:apply-templates/>
        </td>
      </xsl:template>
    
    </xsl:stylesheet>
  5. Open the template descriptor file associated with your publishing template (the .opt file) and set the XSLT stylesheet created in the previous step with the com.oxygenxml.pdf.css.xsl.merged2html5 XSLT extension point:
    <publishing-template>
      ...
      <pdf>
        ...        
        <xslt>
          <extension
            id="com.oxygenxml.pdf.css.xsl.merged2html5"
            file="xslt/merged2html5Extension.xsl"/>
        </xslt>
  6. Create a css folder in the publishing template directory. In this directory, save a custom CSS file with rules that style the glossary structure. For example:
    *[class ~= "glossgroup/table"] {
      width: 100%;
      border: 1px solid black;
      border-collapse: collapse;
    }
    
    *[class ~= "glossgroup/table"] th {
      background-color: lightgray;
    }
    
    *[class ~= "glossgroup/table"] th,
    *[class ~= "glossgroup/table"] td {
      border: 1px solid black;
      padding: 0.3em !important;
      vertical-align: inherit !important;
    }
    
    /* Remove glossSurfaceForm */
    th:nth-of-type(3),
    *[class ~= "glossentry/glossSurfaceForm"] {
      display: none;
    }
    
    /* Discard the default glossterm layout */
    *[class ~= "glossentry/glossterm"] {
      font-size: unset;
      font-weight: unset;
    }
    Note:
    The <glossSurfaceForm> removal part is optional. It is present as an example of how to fully remove a column.
  7. Open the template descriptor file associated with your publishing template (the .opt file) and reference your custom CSS file in the resources element:
    <publishing-template>
      ...
      <pdf>
        ...                
        <resources>            
          <css file="css/custom.css"/>
        </resources> 
  8. Edit the DITA Map PDF - based on HTML5 & CSS transformation scenario.
  9. In the Templates tab, click the Choose Custom Publishing Template link and select your template.
  10. Click OK to save the changes and run the transformation scenario.