0
votes

A customer of ours uses XSL FO for generating PDF output. He has an issue with descriptions in a table where the cells are split over the page end. The limitation is that he uses an XSL editor instead of direct XSL. This editor lets you add XSL snippets, but you cannot access all the levels of the XSL.

Switching to XSL without an editor is not an option.

In XSL a simple solution will look like:

<fo:table-row>
<xsl:attribute name="keep-together.within-page">always</xsl:attribute>
<fo:table-cell>
</fo:table-cell>
</fo:table-row>

But the table-row tag is not accessible from the editor. I can set it on a table-cell level. Is that possible?

So something like:

<fo:table-row>
<fo:table-cell>
<xsl:attribute name="../keep-together.within-page">always</xsl:attribute>
</fo:table-cell>
</fo:table-row>
1
@michael.hor257k Cool, thanks! That was illuminatingLaurentiu L.

1 Answers

0
votes

I don't know what's possible within your editor, but perhaps the following example may help:

XML

<root>
    <row>
        <cell>Alpha</cell>
        <cell>Bravo</cell>
        <cell>Charlie</cell>
    </row>
    <row>
        <cell>Delta</cell>
        <cell>Echo</cell>
    </row>
</root>

XSLT

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="cell[1]">
    <xsl:attribute name="add">True</xsl:attribute>
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

Result

<root>
   <row add="True">
      <cell>Alpha</cell>
      <cell>Bravo</cell>
      <cell>Charlie</cell>
   </row>
   <row add="True">
      <cell>Delta</cell>
      <cell>Echo</cell>
   </row>
</root>

This works because when the first cell is beginning to be processed, the parent row still has no children - so it is still possible to create an attribute and have it "adopted" by the parent row.

If you remove the [1] predicate, you will get an error along the lines of "Cannot write an attribute node when no element start tag is open" when processing any cell beyond the first one in row. Depending on your processor, this error may be fatal or not.