Page 1 of 1

DITA-OT PDF output - table column 1 color

Posted: Tue Feb 10, 2015 9:49 pm
by bdew
We have had a request to change the color of the first table column to something other than the default color. Is there a specific way to do that? I looked through the table-attr.xsl file (under org.dita.pdf2\cfg\fo\attrs) and did not see anything that could be updated/changed. Am I looking in the wrong area or is it even possible?

Thanks!

Re: DITA-OT PDF output - table column 1 color

Posted: Wed Feb 11, 2015 1:20 pm
by Radu
Hi Bryan,

This is possible but there is no easy configuration value you can change in the XSLT stylesheets in order to make it work.
Probably first of all you should somehow mark the DITA tables on which you want this special coloring to appear with a distinct outputclass value like:

Code: Select all

<tgroup cols="2" outputclass="firstColSpecialColor">
................
This is useful in order not to have the same special column color on all DITA tables. If you want it on all DITA tables, then this step is not necessary.

Then you should find the XSLT stylesheet which handles outputting tables to XSL-FO:

OXYGEN_INSTALL_DIR/frameworks/dita/DITA-OT/plugins/org.dita.pdf2/xsl/fo/tables.xsl

In that XSLT there are two templates which match cells in the table (one template matches cells in the header and another in the body):

Code: Select all

<xsl:template match="*[contains(@class, ' topic/thead ')]/*[contains(@class, ' topic/row ')]/*[contains(@class, ' topic/entry ')]">
.........

<xsl:template match="*[contains(@class, ' topic/tbody ')]/*[contains(@class, ' topic/row ')]/*[contains(@class, ' topic/entry ')]">
.................
[code]

In those templates on the output "<fo:table-cell" you can add an extra attribute controlling the background color if the matched cell is the first one in the row and if the cell belongs to a table which has been marked with that special outputclass attribute.
Something like:

[code] <xsl:template match="*[contains(@class, ' topic/tbody ')]/*[contains(@class, ' topic/row ')]/*[contains(@class, ' topic/entry ')]">
<fo:table-cell xsl:use-attribute-sets="tbody.row.entry">
<xsl:call-template name="commonattributes"/>
<xsl:call-template name="applySpansAttrs"/>
<xsl:call-template name="applyAlignAttrs"/>
<xsl:call-template name="generateTableEntryBorder"/>
<!-- MAKE FIRST COLUMN PINK -->
<xsl:if test="ancestor::*[@outputclass='firstColSpecialColor'] and not(preceding-sibling::*)">
<xsl:attribute name="background-color">pink</xsl:attribute>
</xsl:if>
<!-- ADDED XSLT ENDS -->
<fo:block xsl:use-attribute-sets="tbody.row.entry__content">
<xsl:call-template name="processEntryContent"/>
</fo:block>
</fo:table-cell>
</xsl:template>
The proper way to make PDF XSLT customizations is by avoiding to modify directly the XSLT templates in the DITA OT installation:

http://www.oxygenxml.com/doc/ug-oxygen/ ... ation.html

Regards,
Radu

Re: DITA-OT PDF output - table column 1 color

Posted: Wed Feb 11, 2015 5:54 pm
by bdew
Radu,

Thank you. That works great!