Create Multiple Table Styles

Questions about XML that are not covered by the other forums should go here.
cbgarcia
Posts: 10
Joined: Tue Apr 23, 2013 11:48 pm

Create Multiple Table Styles

Post 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.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Create Multiple Table Styles

Post 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
cbgarcia
Posts: 10
Joined: Tue Apr 23, 2013 11:48 pm

Re: Create Multiple Table Styles

Post by cbgarcia »

Thanks, Sorin. It worked!
Phil Champ
Posts: 7
Joined: Wed Nov 26, 2014 3:22 pm

Re: Create Multiple Table Styles

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

Re: Create Multiple Table Styles

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Phil Champ
Posts: 7
Joined: Wed Nov 26, 2014 3:22 pm

Re: Create Multiple Table Styles

Post by Phil Champ »

Thanks for the clarification, Radu.
Post Reply