DITA-OT PDF output - table column 1 color

Post here questions and problems related to editing and publishing DITA content.
bdew
Posts: 11
Joined: Mon Mar 03, 2014 5:11 pm
Location: Shawnee, KS

DITA-OT PDF output - table column 1 color

Post 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!
Bryan
Radu
Posts: 9045
Joined: Fri Jul 09, 2004 5:18 pm

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

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
bdew
Posts: 11
Joined: Mon Mar 03, 2014 5:11 pm
Location: Shawnee, KS

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

Post by bdew »

Radu,

Thank you. That works great!
Bryan
Post Reply