iswinky
iswinky

Reputation: 1969

XSL-FO prevent different elements grouping on new line

The following xsl-fo displays the description and price in a block then gets rendered to a PDF document, however the two elements group together on a new line when there is clearly enough room for the description on the line above, initially I thought a simple "keep-together" would work, but it doesn't make any difference. The red shows the description, and the green shows the price. The price should come after the description, but it shouldn't group with last word in the description if there is enough room on the above line for it.

<fo:block linefeed-treatment="preserve" line-height="8pt">
    <xsl:value-of select="description" />&#160;<xsl:call-template name="price"/>
</fo:block>

xsl-fo

Upvotes: 1

Views: 256

Answers (2)

G. Ken Holman
G. Ken Holman

Reputation: 4393

Because you've used an NBSP, that is gluing the price and the last word together. So you simply need a regular space between the two values:

 <fo:block linefeed-treatment="preserve" line-height="8pt">
    <xsl:value-of select="description" />
    <xsl:text> </xsl:text>
    <xsl:call-template name="price"/>
 </fo:block>

Remember to use <xsl:text> because otherwise a simple space in your stylesheet will be lost.

Upvotes: 2

iswinky
iswinky

Reputation: 1969

I assume the different elements are treated as one, but by simply putting a space before and after the different tags, the description will fill the remaining space on the line above.

<fo:block linefeed-treatment="preserve" line-height="8pt">
    <xsl:value-of select="description" /> &#160; <xsl:call-template name="price"/>
</fo:block>

Upvotes: 0

Related Questions