by Niklas Waller on June 23, 2011
in XML
If you have the need to dedicate height in a printout regardless of if there is a value to print or not, you can proceed this way. There are probably many other ways as well.
I have an XSL:FO document here meant to be outputted as PDF. In one place there should be the same height of a block regardless of if there is a value or not to display. If you use a simple block, it will shrink if there is no value in it. You can create a small table and set the height on the row though to get the desired behavior. Simple solution but not that obvious in the first place perhaps.
<fo:table table-layout="fixed">
<fo:table-column column-width="5cm"/>
<fo:table-body>
<fo:table-row height="0.5cm">
<fo:table-cell>
<fo:block font-size="8pt"><xsl:value-of select="$somevalue"/></fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row height="0.6cm">
<fo:table-cell>
<fo:block font-size="8pt">Some hardcoded value</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table
Tagged as:
pdf,
xsl-fo,
xslt
by Niklas Waller on November 12, 2009
in XML
Todays blog entry will be an open question to any XSL-developer.
Is there a way to use the HTML equivalent ‘rowspan’ in XSL-FO? I want to display a text with a bigger font in the leftmost column. The colums to the right however should consist of a couple of rows with smaller text.
In HTML this would be written something like this:
<table border=”1″ cellpadding=”4″ cellspacing=”0″> <tr> <td rowspan=”3″ style=”font-weight:bold;font-size:14pt”>New Text</td> <td>Value 1</td> <td>Value 2</td> <td></td> </tr> <tr> <td>{someAttribute}</td> <td>{someOtherAttribute}</td> <td></td> </tr> <tr> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> </table> |
and look like this:

Here is the code for XSL-FO without the new leftmost column.
<xsl:template name=”printAddress”> <xsl:param name=”subDocument”/> <fo:table table-layout=”fixed” background-color=”#e0e0e0″ keep-with-next.within-page=”always”>
<fo:table-column column-width=”7.0cm”/> <fo:table-column column-width=”7.0cm”/> <fo:table-column column-width=”2.0cm”/>
<fo:table-body>
<!– Begin Row 1 –> <fo:table-row keep-with-previous=”always”> <fo:table-cell margin-left=”0.2cm” padding-before=”0.1cm” padding-after=”0.1cm”> <fo:block>Value 1</fo:block> </fo:table-cell> <fo:table-cell margin-left=”0.2cm” padding-before=”0.1cm” padding-after=”0.1cm”> <fo:block>Value 2</fo:block> </fo:table-cell> <fo:table-cell margin-left=”0.2cm” padding-before=”0.1cm” padding-after=”0.1cm”> <fo:block/> </fo:table-cell> </fo:table-row> <!– Begin Row 2 –> <fo:table-row keep-with-previous=”always”> <fo:table-cell margin-left=”0.2cm” padding-before=”0.1cm” padding-after=”0.1cm”> <fo:block> <xsl:value-of select=”$subDocument/someAttribute”/> </fo:block> </fo:table-cell> <fo:table-cell margin-left=”0.2cm” padding-before=”0.1cm” padding-after=”0.1cm”> <fo:block> <xsl:value-of select=”$subDocument/someOtherAttribute”/> </fo:block> </fo:table-cell> <fo:table-cell margin-left=”0.2cm” padding-before=”0.1cm” padding-after=”0.1cm”> <fo:block/> </fo:table-cell> </fo:table-row> <!– Begin Row 3 –> <fo:table-row keep-with-previous=”always”> <fo:table-cell margin-left=”0.2cm” padding-before=”0.1cm” padding-after=”0.1cm”> <fo:block>value 3</fo:block> </fo:table-cell> <fo:table-cell margin-left=”0.2cm” padding-before=”0.1cm” padding-after=”0.1cm”> <fo:block>Value 4</fo:block> </fo:table-cell> <fo:table-cell margin-left=”0.2cm” padding-before=”0.1cm” padding-after=”0.1cm”> <fo:block>Value 5</fo:block> </fo:table-cell> </fo:table-row> </fo:table-body> </fo:table> </xsl:template> |
The HTML-equivalent for the above code would be to only remove this row from the provided HTML code at the top:
| <td rowspan=”3″ style=”font-weight:bold;font-size:14pt”>New Text</td> |
How would the XSL-FO code look like to provide the same look as the figure at the top?
Tagged as:
rowspan,
xml,
xsl,
xsl-fo