Luzgan
Luzgan

Reputation: 106

Styling in xsl-fo

I have a problem with understanding styling in xsl-fo. Situation looks like that, I have a table, and I want to style labels for this table (for every row, its first entry). But only for one table. What's the best way to do it?

<table frame="none" outputclass="prefaceTable">
      <tgroup cols="2">
        <colspec colname="COLSPEC0"  colwidth="0.2*" />
        <colspec colname="COLSPEC1"  colwidth="1.0*"/>
        <tbody>
          <row> 
            <entry align="right">Copyright</entry>
            <entry ><p conref="copyright.dita#copyright/statement"></p>
              </entry>
          </row>
          <row>
            <entry align="right">Intended Purpose</entry>
            <entry ><p conref="intendedpurpose.dita#intendedpurpose/statement" ></p></entry>
          </row>
          <row>
            <entry align="right">Conventions Used</entry>
            <entry><p conref="ConventionsUsed.dita#ConventionsUsed/statement"></p></entry>
          </row>
        </tbody>
      </tgroup>
    </table>

EDIT AFTER SOLVED:

And had to be styled in xsl-fo. Basically with help of @Radu and @Kevin I managed to do that, but I had to change it a bit more, since we have DITA 2.0.1, which is also pretty much changed. But in most cases solution given by @Radu (with changing following-sibling to the preceding-sibling), and by @Kevin (of course with changing td's to entries) should work. In my case it didn't, because from what I saw, plugins that we have checking if its the last cell and other things like that, so it wasn't that easy to just overwrite cell.

Upvotes: 1

Views: 937

Answers (2)

Kevin Brown
Kevin Brown

Reputation: 8877

It is not clear what all you are working with. It would be much better if you posted some clear XML and XSL to work with. Let's say you are working with simple tags like table, tr and td.

Your special table is marked with @class='special' ...

In the match you would have for the cell descendant (assuming it is td), you would write:

    <xsl:template match="td[ancestor::table[@class='special']]">
    <xsl:choose>
        <xsl:when test="count(preceding-sibling::td) = 0">
            <!-- your special cell -->
        </xsl:when>
        <xsl:otherwise>
            <!-- all other cells in the special table-->
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

Upvotes: 1

Radu Coravu
Radu Coravu

Reputation: 1924

You can probably set an @outputclass attribute on the table with a certain custom value. Then from the XSLT code you can match entries like:

<xsl:template match="*[contains(@class, ' topic/table ')][@outputclass='specialFirstCell']/*/*[contains(@class, ' topic/tbody ')]/*[contains(@class, ' topic/row ')]/*[contains(@class, ' topic/entry ')][not(following-sibling::*[contains(@class, ' topic/entry ')])]">
            <fo:table-cell xsl:use-attribute-sets="tbody.row.entry">
                <xsl:attribute name="color">red</xsl:attribute>
                <xsl:call-template name="commonattributes"/>
                <xsl:call-template name="applySpansAttrs"/>
                <xsl:call-template name="applyAlignAttrs"/>
                <xsl:call-template name="generateTableEntryBorder"/>
                <fo:block xsl:use-attribute-sets="tbody.row.entry__content">
                    <xsl:call-template name="processEntryContent"/>
                </fo:block>
            </fo:table-cell>
        </xsl:template>

Upvotes: 2

Related Questions