Render reltable content as a table

Post here questions and problems related to editing and publishing DITA content.
matt_k
Posts: 47
Joined: Mon Aug 17, 2020 7:16 pm

Render reltable content as a table

Post by matt_k »

Hi there
How difficult would it be to render content from a reltable as a table with a PDF transform?
Thanks
Matt
julien_lacour
Posts: 679
Joined: Wed Oct 16, 2019 3:47 pm

Re: Render reltable content as a table

Post by julien_lacour »

Hi Matt,

From DITA specs: https://docs.oasis-open.org/dita/dita/v ... table.html
By default, the contents of a <reltable> element are not output for navigation or TOC purposes; they are used only to define relationships that can be expressed as topic-to-topic links. The <relcell> elements can contain <topicref> elements, which are then related to other <topicref> elements in the same row (although not necessarily in the same cell).
But it is possible to force the reltable rendering when using DITA Map PDF - based on HTML5 & CSS transformation, follow these instructions:
  1. First, create a Publishing Template Descriptor file with the following content:

    Code: Select all

    <?xml version="1.0" encoding="UTF-8"?>
    <publishing-template>
      <name>Custom</name>
      <pdf>
        <resources>
          <css file="custom.css"/>
        </resources>
        <xslt>
          <extension file="m2m-display-reltable.xsl" id="com.oxygenxml.pdf.css.xsl.merged2merged"/>
        </xslt>
      </pdf>
    </publishing-template>
    
  2. Then, create the m2m-display-reltable.xsl (New > XSLT Stylesheet) with the following content:

    Code: Select all

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:opentopic="http://www.idiominc.com/opentopic"
      exclude-result-prefixes="#all"
      version="2.0">
      <xsl:template match="opentopic:map//*[contains(@class, ' map/reltable ')]">
        <xsl:copy-of select="."/>
      </xsl:template>
    </xsl:stylesheet>
    
  3. After that, create the custom.css (New > CSS) stylesheet with the following content:

    Code: Select all

    *[class ~= "map/reltable"] {
      display: table;
      border: 1px solid black;
      border-collapse: collapse;
    }
    
    *[class ~= "map/relheader"] {
      display: table-row;
    }
    
    *[class ~= "map/relcolspec"] {
      display: table-cell;
      border: 1px solid black;
      content: attr(type);
      text-align: center;
      font-weight: bold;
      padding: 0.3em;
    }
    
    *[class ~= "map/relrow"] {
      display: table-row;
    }
    
    *[class ~= "map/relcell"] {
      display: table-cell;
      border: 1px solid black;
      padding: 0.3em;
    }
    
  4. Once you've done that, duplicate the DITA Map PDF - based on HTML5 & CSS scenario and refer the opt file in the Templates tab
  5. Finally, run the transformation.
Obviously you can change the files names, just don't forget to refresh their references in the Publishing Template Descriptor.

PS: If you want to use the DITA Map PDF - based on XSL-FO transformation instead, the process will be harder has you will need to generate the table by using XSLT templates only.

Regards,
Julien
matt_k
Posts: 47
Joined: Mon Aug 17, 2020 7:16 pm

Re: Render reltable content as a table

Post by matt_k »

Hi Julien

Thank you, I have managed to get that working using the DITA map HTML CSS transform.

I will now experiment with applying some formatting to the tables.

Is there a way to specify coloumn widths to reltables and to make each reltable appear as a separate table?

Regards

Matt
julien_lacour
Posts: 679
Joined: Wed Oct 16, 2019 3:47 pm

Re: Render reltable content as a table

Post by julien_lacour »

Hi Matt,

You can update the map/reltable rules in the CSS stylesheet to make the reltables bigger and add space between each others, like in this example:

Code: Select all

*[class ~= "map/reltable"] {
  display: table;
  border: 1px solid black;
  border-collapse: collapse;
  margin: 0.2in 0.5in;
  width: 80%;
}
By default the table cells will have equals sizes, is it what you wanted?

Regards,
Julien
Post Reply