Create Multiple Table Styles

Questions about XML that are not covered by the other forums should go here.
cbgarcia
Posts: 10

Create Multiple Table Styles

Thu Jan 23, 2014 11:24 pm

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: 4144

Re: Create Multiple Table Styles

Fri Jan 24, 2014 1:16 pm

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

Re: Create Multiple Table Styles

Fri Jan 24, 2014 7:26 pm

Thanks, Sorin. It worked!
Phil Champ
Posts: 7

Re: Create Multiple Table Styles

Thu Jun 25, 2015 1:26 pm

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: 5376

Re: Create Multiple Table Styles

Thu Jun 25, 2015 1:43 pm

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

Re: Create Multiple Table Styles

Thu Jun 25, 2015 2:49 pm

Thanks for the clarification, Radu.

Return to “General XML Questions”

Who is online

Users browsing this forum: No registered users and 1 guest