Page 1 of 1

Create Multiple Table Styles

Posted: Thu Jan 23, 2014 11:24 pm
by cbgarcia
Is there a way in Oxygen XML to create two or more types of table such that when I generate a webhelp and PDF output, the tables will have different colors in the heading. For example, table 1 will have blue background in the heading, table 2 will have yellow, etc.

Re: Create Multiple Table Styles

Posted: Fri Jan 24, 2014 1:16 pm
by sorin_ristache
Hello,

That is possible by marking each type of table with the attribute outputclass in the DITA XML topic files. This will create a different category of tables for each distinct value of the outputclass attribute. For example:

Code: Select all

<table outputclass="blue-table">
. . .
</table>


<table outputclass="yellow-table">
. . .
</table>
For the Webhelp output you should set the style in a CSS stylesheet that you set in the parameter args.css of the DITA Webhelp transformation. Also set the parameter args.copycss to true. In the Webhelp pages the table will be <table class="table blue-table">, so in the CSS stylesheet you can use for example:

Code: Select all

table.blue-table  thead {
background-color:blue;
}

table.yellow-table thead {
background-color:yellow;
}
For the PDF output you have to customize the stylesheet:

[Oxygen-install-dir]\frameworks\dita\DITA-OT\plugins\org.dita.pdf2\cfg\fo\attrs\tables-attr.xsl

by adding the following in the XSLT attribute set with name="thead.row.entry":

Code: Select all

      <xsl:attribute name="background-color">
<xsl:choose>
<xsl:when test="ancestor-or-self::*[contains(@class, ' topic/table ')][@outputclass='blue-table']">blue</xsl:when>
<xsl:when test="ancestor-or-self::*[contains(@class, ' topic/table ')][@outputclass='yellow-table']">yellow</xsl:when>
<xsl:otherwise>antiquewhite</xsl:otherwise>
</xsl:choose>
</xsl:attribute>

Regards,
Sorin

Re: Create Multiple Table Styles

Posted: Fri Jan 24, 2014 7:26 pm
by cbgarcia
Thanks, Sorin. It worked!

Re: Create Multiple Table Styles

Posted: Thu Jun 25, 2015 1:26 pm
by Phil Champ
This XPath expression is shorter and does the same job:

Code: Select all

<xsl:when test="ancestor::table[contains(@outputclass,'blue-table')]">blue</xsl:when>

Re: Create Multiple Table Styles

Posted: Thu Jun 25, 2015 1:43 pm
by Radu
Hi Phil,

The DITA vocabulary can be specialized (for example I can create a DITA vocabulary extension which renames the <table> element to <myTable>) and the @class attribute value on each element shows its inheritance.
So usually when writing XSLT for DITA you need to match the @class attribute of an element instead of matching its name in order to have the same stylesheet work with a potential DITA specialization which renamed that element.
Of course, if you consider you will never create a DITA specialization to rename the <table> element you can match on the element name.

Regards,
Radu

Re: Create Multiple Table Styles

Posted: Thu Jun 25, 2015 2:49 pm
by Phil Champ
Thanks for the clarification, Radu.