Page 1 of 1
Render reltable content as a table
Posted: Wed Mar 02, 2022 8:46 pm
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
Re: Render reltable content as a table
Posted: Thu Mar 03, 2022 12:51 pm
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:
- 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>
- 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>
- 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;
}
- Once you've done that, duplicate the DITA Map PDF - based on HTML5 & CSS scenario and refer the opt file in the Templates tab
- 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
Re: Render reltable content as a table
Posted: Thu Mar 17, 2022 3:17 pm
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
Re: Render reltable content as a table
Posted: Fri Mar 18, 2022 11:54 am
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