[xsl] [XSL-FO] Linebreaks on a page break (linefeed-treatment)

Subject: [xsl] [XSL-FO] Linebreaks on a page break (linefeed-treatment)
From: "Mathias Leclercq mathias.leclercq@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 28 Jun 2018 06:33:16 -0000
Hi everyone,

I'm using XSL-T and XSL-FO to produce PDF (A4) reports using data from forms
filled by user in a third-party software (that output XML). Users can have any
sorts of input, included large text area they can fill as they want (no
control over the content size).

-----------------------------------------------------------------------------
-----------------------------
I'm using
- XSLT Engine: Altova (built-in RaptorXML XSLT engine) for XSL development
- XSLT version 1.0
- FOP Processor: Apache FOP 1.0
-----------------------------------------------------------------------------
-----------------------------

The issue I came across is that whenever the text area is filled with enough
data to cause a page break, and when there are linebreaks at the exact moment
the page break occurs, the FOP processor issues a null pointer exception.
Below is the part of the XSL-FO that is causing an issue.

The linefeed-treatment="preserve" is to keep the format from the form to the
PDF and the keep-together.within-page="always" ("auto" here to show the issue)
is a workaround I found to resolve this issue but that I cannot keep because
data is lost when the text span more than 1 page.

Is there a problem somewhere in my code? is it related to the FOP processor?
I can provide with the complete files if necessary

Thank you very much for any help you can provide

-----------------------------------------------------------------------------
------------------------
XSL-FO after transformation
-----------------------------------------------------------------------------
------------------------

<fo:block space-before="5mm" text-align="justify">
	<fo:block linefeed-treatment="preserve" keep-together.within-page="auto">
		<fo:block>
			<fo:inline/>
			<fo:inline> TEST WITH LOTS OF LINEBREAKS



********************************************
	somwehere here there's a page break
********************************************




		END OF TEST WITH LINEBREAKS </fo:inline>
		</fo:block>
	</fo:block>
</fo:block>

-----------------------------------------------------------------------------
------------------------
XML from third-party software (trimmed)
-----------------------------------------------------------------------------
------------------------

<?xml version="1.0" encoding="UTF-8"?>
<FM024_BIL_RapportConsultation>
	<ZTXT_lettre style="txtArea" toPrint="1"> TEST WITH LOTS OF LINEBREAKS








END OF TEST WITH LINEBREAKS </ZTXT_lettre>
</FM024_BIL_RapportConsultation>

-----------------------------------------------------------------------------
------------------------
XSL-T template to match the @style = 'txtArea'
-----------------------------------------------------------------------------
------------------------

<xsl:template match="*[attribute::style='txtArea']">
	<xsl:param name="pLang" select="$gLang"/>
	<xsl:param name="pTitleTemplate"/>
	<xsl:param name="pKeepTogetherWithinPage" select="'always'"/>
	<xsl:param name="pStartWith" select="''"/>
	<xsl:if test="self::node()/text() != ''"> <!-- display content only if text
area is not empty -->
		<fo:block linefeed-treatment="preserve"
keep-together.within-page="{$pKeepTogetherWithinPage}">
			<xsl:if test="$pTitleTemplate != ''">
				<fo:block>
					<xsl:copy-of select="$pTitleTemplate"/>
				</fo:block>
			</xsl:if>
			<fo:block>
				<xsl:call-template name="gLangString">
					<xsl:with-param name="pLang" select="$pLang"/>
					<xsl:with-param name="pString" select="$pStartWith"/>
				</xsl:call-template>
				<fo:inline>
					<xsl:value-of select="self::node()/text()"/>
				</fo:inline>
			</fo:block>
		</fo:block>
	</xsl:if>
</xsl:template>

-----------------------------------------------------------------------------
------------------------
Most of the complete XSL-FO (removed all the unrelated stuff)
-----------------------------------------------------------------------------
------------------------

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format";>
	<fo:layout-master-set>
		<fo:simple-page-master master-name="coverPage" margin="5mm"
page-height="297mm" page-width="210mm" reference-orientation="0"
writing-mode="lr-tb">
			<fo:region-body margin-top="25mm" margin-bottom="25mm" margin-left="45mm"
margin-right="5mm"/>
			<fo:region-after extent="20mm" precedence="true" display-align="before"/>
			<fo:region-start extent="40mm"/>
		</fo:simple-page-master>
		<fo:simple-page-master master-name="repeatablePage" margin="5mm"
page-height="297mm" page-width="210mm" reference-orientation="0"
writing-mode="lr-tb">
			<fo:region-body margin-top="30mm" margin-bottom="25mm" margin-left="20mm"
margin-right="20mm"/>
			<fo:region-after extent="20mm" precedence="true" display-align="before"/>
		</fo:simple-page-master>
		<fo:page-sequence-master master-name="pageSequence">
			<fo:single-page-master-reference master-reference="coverPage"/>
			<fo:repeatable-page-master-reference master-reference="repeatablePage"
maximum-repeats="no-limit"/>
		</fo:page-sequence-master>
	</fo:layout-master-set>
	<fo:page-sequence master-reference="pageSequence" font-family="sans-serif"
font-weight="normal">
		<fo:static-content flow-name="xsl-region-after">
			<fo:block text-align="right" font-size="10" color="#083E70">
				Page <fo:page-number/> de <fo:page-number-citation
ref-id="endDoc"/></fo:block>
			<fo:block text-align="center" font-size="8" color="#083E70"
space-before="8mm">
				<fo:block>ADRESS LINE 1</fo:block>
				<fo:block>ADRESS LINE 2</fo:block>
			</fo:block>
		</fo:static-content>
		<fo:static-content flow-name="xsl-region-start">
			<fo:block/>
			<fo:block-container color="#083E70" border-end-color="#083E70"
border-end-width="1pt" border-end-style="solid"
block-progression-dimension="235mm">
				<fo:block/>
				<fo:block space-before="10mm" space-after="10mm" font-weight="bold"
text-decoration="underline"/>
			</fo:block-container>
		</fo:static-content>
		<fo:flow flow-name="xsl-region-body" font-size="10pt">
			<fo:block space-before="5mm" text-align="justify" font-family="monospace">
				<fo:block linefeed-treatment="preserve"
keep-together.within-page="always">
					<fo:block>
						<fo:inline/>
						<fo:inline> TEST WITH LOTS OF LINEBREAKS








END OF TEST WITH LINEBREAKS </fo:inline>
					</fo:block>
				</fo:block>
			</fo:block>
			<fo:block id="endDoc"/>
		</fo:flow>
	</fo:page-sequence>
</fo:root>

Current Thread