vikash kumar
vikash kumar

Reputation: 11

XSL-FO: PDF output: Text with a space is allowed to wrap lines inside a table column

We're facing a formatting issue with publishing PDF output from XML content. In table columns, text in a table cell contains some text (model numbers) for example,

AD150, OP834,
HT78J, QW09T,
OL560, PQ
UW, AG800, XN280

as highlighted, the model names mentioned are split into two lines if there is a space in the name ("PQ UW"). This happens even if enough cell width is available to accomodate the text after the space. However, in case when there is no space, the text splits at regular column width.

Please suggest the solution to fix this, so that the text always appear in the same line (without breaking into a new line) even if there is a space within them. Text should break at regular cell width only.

Upvotes: 1

Views: 999

Answers (2)

Kevin Brown
Kevin Brown

Reputation: 8877

The sample XSL provided will work well if the input XML has separate tags for each model number. If it does not and the source XML is something like this:

<modellist>OL560, PQ UW, AG800</modellist>

Then you would write a recursive template to process through each character in the list, writing the output into a variable (search for recursive XSL template for splitting for an example). It would be not that difficult to do. You would output any space character that follows a "," normally but replace any space character not following a "," as above (with a non-breaking space).

Start here for some inspiration:

Breaking long lines

Upvotes: 1

C. M. Sperberg-McQueen
C. M. Sperberg-McQueen

Reputation: 25054

One cheap thing to try: when you render the model names, change blanks to character U+00A0, non-breaking space. Something like this:

<xsl:template match="model-name">
  <xsl:value-of select="translate(.,' ','&#xA0;')"/>
</xsl:template>

Upvotes: 0

Related Questions