I am generating PDF using Apache FOP XSL file format.
My requirements are
Tabular data in PDF
Table size is large so the Same table extended to multiple pages (width-wise, few columns in first page others are on the next page)
Page 1 has 3 columns (C1, C2, C3)
Page 2 has 5 columns (C4, C5, C6, C7, C8)
Few cells may have multiline data
Problem description:
When Page-2 has multiline data for Row 4, Column 4, so its row height increased as per content
But in Page-1 row 4 has row height as a single line.
I want to have the same row height across all pages of the same table when any cell data is multiline of any page.
Here is XSL file if needed:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="1.0">
<!-few params declaration->
<xsl:template match="/rs">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="data-template-1" page-height="11.0in" page-width="17.0in"
margin-top="0.5in" margin-bottom="1.0in" margin-left="0.5in"
margin-right="0.5in">
<fo:region-body margin-top="1.5in" margin-bottom="0.8in"/>
<fo:region-before extent="0.7in"/>
<fo:region-after/>
</fo:simple-page-master>
<fo:simple-page-master master-name="data-template-2" page-height="11.0in" page-width="17.0in"
margin-top="0.5in" margin-bottom="1.0in" margin-left="0.5in"
margin-right="0.5in">
<fo:region-body margin-top="1.5in" margin-bottom="0.8in"/>
<fo:region-before extent="0.7in"/>
<fo:region-after/>
</fo:simple-page-master>
</fo:layout-master-set>
<xsl:for-each select="rb">
<xsl:variable name="current-initial-page-number" select="$param.initialPageNumber + (position() * $pagesPerTable)" />
<fo:page-sequence master-reference="data-template-1" initial-page-number="{$current-initial-page-number}"
font-size="{$cdrFontSize}" font-family="{$cdrFontFamily}" line-height="10.2pt">
<fo:flow flow-name="xsl-region-body">
<fo:table table-layout="fixed" width="100%" space-after.optimum="{$cdrInfoTableSpaceAfter}" border-width="0.4mm" border-style="solid">
<fo:table-column column-width="23.1mm"/>
<fo:table-column column-width="23.1mm"/>
<fo:table-column column-width="18.9mm"/>
<fo:table-header text-align="center" display-align="center">
<fo:table-row font-weight="bold" background-color="rgb(230,230,230)">
<xsl:call-template name="cdr_table_cell">
<xsl:with-param name="cellValue" select="'C1'"/>
</xsl:call-template>
<xsl:call-template name="cdr_table_cell">
<xsl:with-param name="cellValue" select="'C2'"/>
</xsl:call-template>
<xsl:call-template name="cdr_table_cell">
<xsl:with-param name="cellValue" select="'C3"/>
</xsl:call-template>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<xsl:for-each select="r">
<fo:table-row text-align="left" display-align="before">
<xsl:call-template name="cdr_table_cell">
<xsl:with-param name="cellValue" select="c[#n='C1']"/>
</xsl:call-template>
<xsl:call-template name="cdr_table_cell">
<xsl:with-param name="cellValue" select="c[#n='C12']"/>
</xsl:call-template>
<xsl:call-template name="cdr_table_cell">
<xsl:with-param name="cellValue" select="c[#n='C3']"/>
</xsl:call-template>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:flow>
</fo:page-sequence>
<fo:page-sequence master-reference="data-template-2"
font-size="{$cdrFontSize}" font-family="{$cdrFontFamily}" line-height="10.2pt">
<fo:flow flow-name="xsl-region-body">
<fo:table table-layout="fixed" width="100%" space-after.optimum="{$cdrInfoTableSpaceAfter}" border-width="0.4mm" border-style="solid">
<fo:table-column column-width="88.2mm"/>
<fo:table-column column-width="88.2mm"/>
<fo:table-column column-width="48.3mm"/>
<fo:table-column column-width="23.1mm"/>
<fo:table-column column-width="54.6mm"/>
<fo:table-header text-align="center" display-align="center">
<fo:table-row font-weight="bold" background-color="rgb(230,230,230)">
<xsl:call-template name="cdr_table_cell">
<xsl:with-param name="cellValue" select="'C4'"/>
</xsl:call-template>
<xsl:call-template name="cdr_table_cell">
<xsl:with-param name="cellValue" select="'C5'"/>
</xsl:call-template>
<xsl:call-template name="cdr_table_cell">
<xsl:with-param name="cellValue" select="'C6'"/>
</xsl:call-template>
<xsl:call-template name="cdr_table_cell">
<xsl:with-param name="cellValue" select="'C7'"/>
</xsl:call-template>
<xsl:call-template name="cdr_table_cell">
<xsl:with-param name="cellValue" select="'C8'"/>
</xsl:call-template>
</fo:table-row>R
</fo:table-header>
<fo:table-body>
<xsl:for-each select="r">
<fo:table-row text-align="left" display-align="before">
<xsl:call-template name="cdr_table_cell">
<xsl:with-param name="cellValue" select="c[#n='C4']"/>
</xsl:call-template>
<xsl:call-template name="cdr_table_cell">
<xsl:with-param name="cellValue" select="c[#n='C5']"/>
</xsl:call-template>
<xsl:call-template name="cdr_table_cell">
<xsl:with-param name="cellValue" select="c[#n='C6']"/>
</xsl:call-template>
<xsl:call-template name="cdr_table_cell">
<xsl:with-param name="cellValue" select="c[#n='C7']"/>
</xsl:call-template>
<xsl:call-template name="cdr_table_cell">
<xsl:with-param name="cellValue" select="c[#n='C8']"/>
</xsl:call-template>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:flow>
</fo:page-sequence>
</xsl:for-each>
</fo:root>
</xsl:template>
<xsl:template name="cdr_table_cell">
<xsl:param name="cellValue"/>
<fo:table-cell border-width="0.4mm" border-style="solid">
<fo:block-container overflow="hidden">
<fo:block margin-left="0.5mm" margin-top="0.3mm">
<xsl:call-template name="zero_width_space_1">
<xsl:with-param name="data" select="$cellValue"/>
</xsl:call-template>
</fo:block>
</fo:block-container>
</fo:table-cell>
</xsl:template>
<!-- The following templates are used to add empty space character to data, so that FOP can break (wrap) the word -->
<xsl:template name="zero_width_space_1">
<xsl:param name="data"/>
<xsl:param name="counter" select="0"/>
<xsl:choose>
<xsl:when test="$counter <= string-length($data)">
<xsl:value-of select='concat(substring($data,$counter,1),"")'/>
<xsl:call-template name="zero_width_space_2">
<xsl:with-param name="data" select="$data"/>
<xsl:with-param name="counter" select="$counter+1"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="' '"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="zero_width_space_2">
<xsl:param name="data"/>
<xsl:param name="counter"/>
<xsl:value-of select='concat(substring($data,$counter,1),"")'/>
<xsl:call-template name="zero_width_space_1">
<xsl:with-param name="data" select="$data"/>
<xsl:with-param name="counter" select="$counter+1"/>
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>
What I don't want
Fixed row height as it wastes page space even if all data is accumulated in a single line.
Format the full table twice: once for each page.
For the first copy of the table, make everything after column 3 be white or transparent.
For the second copy of the table, make everything in columns 1 to 3 be white or transparent and also add a negative margin on the table (and set it back to 0 in the table cells) so that columns 1 to 3 are off the left side of the page.
Note that if you were using AH Formatter, you could use the Spread Page Master extension (see https://www.antenna.co.jp/AHF/help/v70e/ahf-spread.html) and make a region that spans both pages.
Related
I'm trying to generate a pdf using xsl + xml, but Im having problems on a part of the document where there is some lines of text with line breaks.
When generating the document it did not keep those line breaks.
I have tried everything, and Im completely stuck.
My code is:
<fo:table-row>
<fo:table-cell margin-right="0mm" margin-left="0mm"
margin-bottom="0mm" margin-top="0mm"
xsl:use-attribute-sets="bordergris" number-columns-spanned="5">
<fo:block xsl:use-attribute-sets="titoldades"
space-before.optimum="0pt" space-after.optimum="0pt"
keep-together="always" >
More info:
</fo:block>
<fo:block xsl:use-attribute-sets="dades"
space-before.optimum="0pt" space-after.optimum="0pt"
keep-together="always" linefeed-treatment="preserve">
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="/Response/DataList/Data/MoreInfo"/>
<xsl:with-param name="replace" select="' '" />
<xsl:with-param name="with" select="'<fo:block/>'"/>
</xsl:call-template>
</fo:block>
</fo:table-cell>
</fo:table-row>
Which use a template function:
<xsl:template name="replace-string">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="with"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$with"/>
<xsl:call-template name="replace-string">
<xsl:with-param name="text"
select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="with" select="$with"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
And the resulting text appears with the hardcoded text "<fo:block/>" instead of applying the line break.
What am I doing wrong?
Thanks!!!
The important thing is to put the following properties inside the fo:block:
inefeed-treatment="preserve" white-space-collapse="false" white-space-treatment="preserve"
And then do the replace with the following:
<fo:block xsl:use-attribute-sets="dades"
linefeed-treatment="preserve" white-space-collapse="false" white-space-treatment="preserve">
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="/Response/DataList/Data/MoreInfo"/>
<xsl:with-param name="replace" select="' '" />
<xsl:with-param name="with" select="'
'"/>
</xsl:call-template>
I'm new to the XSLT FO world and came across an issue. I have my XSLT that works well with the fop-0.95 processor and generates the PDF, but after I upgraded to fop-2.3, it left my first page blank and started the PDF body from the second page (my PDF has a header that appears fine on the first page).
I figured out where the issue was, and it was because I had the margin-top value set to 3 inches in the "fo:region-body" tag within the "fo:layout-master-set" (please see screenshot). I had to change the margin-top from 3 inches to 2.5 inches for the body of my PDF to appear like it was while using fop-0.95.
<?xml version="1.0" encoding="UTF-8"?>
<!--Designed and generated by Altova StyleVision Enterprise Edition 2013 (x64) - see http://www.altova.com/stylevision for more information.-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:altova="http://www.altova.com" xmlns:altovaext="http://www.altova.com/xslt-extensions" xmlns:clitype="clitype" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:iso4217="http://www.xbrl.org/2003/iso4217" xmlns:ix="http://www.xbrl.org/2008/inlineXBRL" xmlns:java="java" xmlns:link="http://www.xbrl.org/2003/linkbase" xmlns:sps="http://www.altova.com/StyleVision/user-xpath-functions" xmlns:xbrldi="http://xbrl.org/2006/xbrldi" xmlns:xbrli="http://www.xbrl.org/2003/instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg" exclude-result-prefixes="altova altovaext clitype fn iso4217 ix java link sps xbrldi xbrli xlink xs xsi">
<xsl:output version="1.0" method="xml" encoding="UTF-8" indent="no"/>
<xsl:param name="SV_OutputFormat" select="'PDF'"/>
<xsl:variable name="XML" select="/"/>
<xsl:variable name="fo:layout-master-set">
<fo:layout-master-set>
<fo:simple-page-master master-name="page-master-0-even" margin-left="0.50in" margin-right="0.50in" page-height="11in" page-width="8.50in" margin-top="0.30in" margin-bottom="0.30in">
<fo:region-body margin-top="0.45in" margin-bottom="0.45in" column-count="1" column-gap="0.50in"/>
<fo:region-before region-name="even-page-header" overflow="hidden" extent="0.45in"/>
<fo:region-after region-name="even-page-footer" overflow="hidden" extent="0.45in"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="page-master-0-odd" margin-left="0.50in" margin-right="0.50in" page-height="11in" page-width="8.50in" margin-top="0.30in" margin-bottom="0.30in">
<fo:region-body margin-top="0.45in" margin-bottom="0.45in" column-count="1" column-gap="0.50in"/>
<fo:region-before region-name="odd-page-header" overflow="hidden" extent="0.45in"/>
<fo:region-after region-name="odd-page-footer" overflow="hidden" extent="0.45in"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="page-master-0-even-first" margin-left="0.50in" margin-right="0.50in" page-height="11in" page-width="8.50in" margin-top="0.30in" margin-bottom="0.30in">
<fo:region-body margin-top="3in" margin-bottom="0.45in" column-count="1" column-gap="0.50in"/>
<fo:region-before region-name="even-page-header-first" overflow="hidden" extent="3in"/>
<fo:region-after region-name="even-page-footer" overflow="hidden" extent="0.45in"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="page-master-0-odd-first" margin-left="0.50in" margin-right="0.50in" page-height="11in" page-width="8.50in" margin-top="0.30in" margin-bottom="0.30in">
<fo:region-body margin-top="3in" margin-bottom="0.45in" column-count="1" column-gap="0.50in"/>
<fo:region-before region-name="odd-page-header-first" overflow="hidden" extent="3in"/>
<fo:region-after region-name="odd-page-footer" overflow="hidden" extent="0.45in"/>
</fo:simple-page-master>
<fo:page-sequence-master master-name="page-master-0">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference master-reference="page-master-0-even-first" odd-or-even="even" page-position="first"/>
<fo:conditional-page-master-reference master-reference="page-master-0-odd-first" odd-or-even="odd" page-position="first"/>
<fo:conditional-page-master-reference master-reference="page-master-0-even" odd-or-even="even"/>
<fo:conditional-page-master-reference master-reference="page-master-0-odd" odd-or-even="odd"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>
</xsl:variable>
<xsl:variable name="altova:nPxPerIn" select="96"/>
<xsl:template match="/">
<fo:root>
<xsl:copy-of select="$fo:layout-master-set"/>
<fo:declarations>
<x:xmpmeta xmlns:x="adobe:ns:meta/">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">
<xmp:CreatorTool>Altova StyleVision Enterprise Edition 2013 (x64) (http://www.altova.com)</xmp:CreatorTool>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
</fo:declarations>
<fo:page-sequence force-page-count="no-force" master-reference="page-master-0" initial-page-number="auto" format="1">
<fo:static-content flow-name="odd-page-header-first">
<fo:block-container overflow="hidden" display-align="before">
<fo:block>
<xsl:for-each select="$XML">
<xsl:for-each select="DOCUMENT">
<xsl:for-each select="DATA">
<xsl:for-each select="STRUCT">
<xsl:for-each select="FIELD[FNAME='nfHeaderDtls']">
<xsl:for-each select="STRUCT">
<fo:block-container font-family="Arial" font-size="10pt" width="7.490000in" height="3.000000in" overflow="hidden">
<fo:block-container absolute-position="absolute" font-family="Arial" font-size="9pt" height="1.21in" left="4.55in" top="1.75in" width="2.90in" overflow="hidden">
<fo:block>
<xsl:for-each select="FIELD[FNAME='Name']">
<xsl:for-each select="VALUE">
<xsl:variable name="value-of-template_1">
<xsl:apply-templates/>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains(string($value-of-template_1),'')">
<fo:block>
<xsl:copy-of select="$value-of-template_1"/>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:inline>
<xsl:copy-of select="$value-of-template_1"/>
</fo:inline>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
<fo:block/>
</fo:block>
</fo:block-container>
</fo:block-container>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</fo:block>
</fo:block-container>
</fo:static-content>
<fo:static-content flow-name="even-page-header-first">
<fo:block-container overflow="hidden" display-align="before">
<fo:block>
<xsl:for-each select="$XML">
<xsl:for-each select="DOCUMENT">
<xsl:for-each select="DATA">
<xsl:for-each select="STRUCT">
<xsl:for-each select="FIELD[FNAME='nfHeaderDtls']">
<xsl:for-each select="STRUCT">
<fo:block-container font-family="Arial" font-size="10pt" width="7.490000in" height="3.000000in" overflow="hidden">
<fo:block-container absolute-position="absolute" font-family="Arial" font-size="9pt" height="1.21in" left="4.55in" top="1.75in" width="2.90in" overflow="hidden">
<fo:block>
<xsl:for-each select="FIELD[FNAME='Name']">
<xsl:for-each select="VALUE">
<xsl:variable name="value-of-template_1">
<xsl:apply-templates/>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains(string($value-of-template_1),'')">
<fo:block>
<xsl:copy-of select="$value-of-template_1"/>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:inline>
<xsl:copy-of select="$value-of-template_1"/>
</fo:inline>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
<fo:block/>
</fo:block>
</fo:block-container>
</fo:block-container>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</fo:block>
</fo:block-container>
</fo:static-content>
<fo:static-content flow-name="odd-page-header">
<fo:block-container overflow="hidden" display-align="before">
<fo:block>
<xsl:for-each select="$XML">
<xsl:for-each select="DOCUMENT">
<xsl:for-each select="DATA">
<xsl:for-each select="STRUCT">
<xsl:for-each select="FIELD[FNAME='nfHeaderDtls']">
<xsl:for-each select="STRUCT">
<fo:block-container font-family="Arial" font-size="10pt" width="7.500000in" height="0.500000in" overflow="hidden">
<fo:block-container absolute-position="absolute" height="0.19in" left="0in" top="0in" width="2.78in" overflow="hidden">
<fo:block>
<fo:inline>
<xsl:text>Identifier: </xsl:text>
</fo:inline>
<xsl:for-each select="FIELD[FNAME='caseReference']">
<xsl:for-each select="VALUE">
<xsl:variable name="value-of-template_27">
<xsl:apply-templates/>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains(string($value-of-template_27),'')">
<fo:block>
<xsl:copy-of select="$value-of-template_27"/>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:inline>
<xsl:copy-of select="$value-of-template_27"/>
</fo:inline>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</fo:block>
</fo:block-container>
</fo:block-container>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</fo:block>
</fo:block-container>
</fo:static-content>
<fo:static-content flow-name="even-page-header">
<fo:block-container overflow="hidden" display-align="before">
<fo:block>
<xsl:for-each select="$XML">
<xsl:for-each select="DOCUMENT">
<xsl:for-each select="DATA">
<xsl:for-each select="STRUCT">
<xsl:for-each select="FIELD[FNAME='nfHeaderDtls']">
<xsl:for-each select="STRUCT">
<fo:block-container font-family="Arial" font-size="10pt" width="7.500000in" height="0.500000in" overflow="hidden">
<fo:block-container absolute-position="absolute" height="0.19in" left="0in" top="0in" width="2.78in" overflow="hidden">
<fo:block>
<fo:inline>
<xsl:text>Identifier: </xsl:text>
</fo:inline>
<xsl:for-each select="FIELD[FNAME='caseReference']">
<xsl:for-each select="VALUE">
<xsl:variable name="value-of-template_27">
<xsl:apply-templates/>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains(string($value-of-template_27),'')">
<fo:block>
<xsl:copy-of select="$value-of-template_27"/>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:inline>
<xsl:copy-of select="$value-of-template_27"/>
</fo:inline>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</fo:block>
</fo:block-container>
</fo:block-container>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</fo:block>
</fo:block-container>
</fo:static-content>
<fo:static-content flow-name="odd-page-footer">
<fo:block-container height="0.45in" overflow="hidden" display-align="after">
<fo:block>
<fo:block-container font-family="Arial" font-size="10pt" width="7.490000in" height="0.500000in" overflow="hidden">
<fo:block-container absolute-position="absolute" height="0.40in" left="0in" top="0in" width="4.04in" overflow="hidden">
<fo:block>
<fo:inline>
<xsl:text>My Test Form</xsl:text>
</fo:inline>
<fo:block/>
<fo:inline>
<xsl:text>Test Text</xsl:text>
</fo:inline>
</fo:block>
</fo:block-container>
<fo:block-container absolute-position="absolute" height="0.38in" left="4.82in" text-align="right" top="0in" width="2.63in" overflow="hidden">
<fo:block>
<fo:inline font-weight="bold">
<xsl:text>Page: </xsl:text>
</fo:inline>
<fo:page-number font-weight="bold"/>
<fo:inline font-weight="bold">
<xsl:text> of </xsl:text>
</fo:inline>
<fo:page-number-citation ref-id="SV_RefID_PageTotal" font-weight="bold"/>
</fo:block>
</fo:block-container>
</fo:block-container>
</fo:block>
</fo:block-container>
</fo:static-content>
<fo:static-content flow-name="even-page-footer">
<fo:block-container height="0.45in" overflow="hidden" display-align="after">
<fo:block>
<fo:block-container font-family="Arial" font-size="10pt" width="7.490000in" height="0.500000in" overflow="hidden">
<fo:block-container absolute-position="absolute" height="0.40in" left="0in" top="0in" width="4.04in" overflow="hidden">
<fo:block>
<fo:inline>
<xsl:text>My Test Form</xsl:text>
</fo:inline>
<fo:block/>
<fo:inline>
<xsl:text>Test Text</xsl:text>
</fo:inline>
</fo:block>
</fo:block-container>
<fo:block-container absolute-position="absolute" height="0.38in" left="4.82in" text-align="right" top="0in" width="2.63in" overflow="hidden">
<fo:block>
<fo:inline font-weight="bold">
<xsl:text>Page: </xsl:text>
</fo:inline>
<fo:page-number font-weight="bold"/>
<fo:inline font-weight="bold">
<xsl:text> of </xsl:text>
</fo:inline>
<fo:page-number-citation ref-id="SV_RefID_PageTotal" font-weight="bold"/>
</fo:block>
</fo:block-container>
</fo:block-container>
</fo:block>
</fo:block-container>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<fo:block>
<xsl:for-each select="$XML">
<xsl:for-each select="DOCUMENT">
<xsl:for-each select="DATA">
<xsl:for-each select="STRUCT">
<fo:block-container font-family="Arial" font-size="10pt" width="7.500000in" height="7.040000in" overflow="hidden">
<fo:block-container absolute-position="absolute" font-family="Arial" font-size="13pt" font-weight="bold" height="0.28in" left="0in" text-align="center" top="0in" width="7.46in" overflow="hidden">
<fo:block>
<fo:inline>
<xsl:text>Form Body Starts Here </xsl:text>
</fo:inline>
<xsl:for-each select="FIELD[FNAME='nfFormTitle']">
<xsl:for-each select="VALUE">
<xsl:variable name="value-of-template_28">
<xsl:apply-templates/>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains(string($value-of-template_28),'')">
<fo:block>
<xsl:copy-of select="$value-of-template_28"/>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:inline>
<xsl:copy-of select="$value-of-template_28"/>
</fo:inline>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
<fo:inline>
<xsl:text> Test Test</xsl:text>
</fo:inline>
</fo:block>
</fo:block-container>
</fo:block-container>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</fo:block>
<fo:block id="SV_RefID_PageTotal"/>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template name="altova:double-backslash">
<xsl:param name="text"/>
<xsl:param name="text-length"/>
<xsl:variable name="text-after-bs" select="substring-after($text, '\')"/>
<xsl:variable name="text-after-bs-length" select="string-length($text-after-bs)"/>
<xsl:choose>
<xsl:when test="$text-after-bs-length = 0">
<xsl:choose>
<xsl:when test="substring($text, $text-length) = '\'">
<xsl:value-of select="concat(substring($text,1,$text-length - 1), '\\')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(substring($text,1,$text-length - $text-after-bs-length - 1), '\\')"/>
<xsl:call-template name="altova:double-backslash">
<xsl:with-param name="text" select="$text-after-bs"/>
<xsl:with-param name="text-length" select="$text-after-bs-length"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="altova:MakeValueAbsoluteIfPixels">
<xsl:param name="sValue"/>
<xsl:variable name="sBeforePx" select="substring-before($sValue, 'px')"/>
<xsl:choose>
<xsl:when test="$sBeforePx">
<xsl:variable name="nLengthOfInteger">
<xsl:call-template name="altova:GetCharCountOfIntegerAtEndOfString">
<xsl:with-param name="sText" select="$sBeforePx"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="nPosOfInteger" select="string-length($sBeforePx) - $nLengthOfInteger + 1"/>
<xsl:variable name="nValuePx" select="substring($sBeforePx, $nPosOfInteger)"/>
<xsl:variable name="nValueIn" select="number($nValuePx) div number($altova:nPxPerIn)"/>
<xsl:variable name="nLengthBeforeInteger" select="string-length($sBeforePx) - $nLengthOfInteger"/>
<xsl:variable name="sRest">
<xsl:call-template name="altova:MakeValueAbsoluteIfPixels">
<xsl:with-param name="sValue" select="substring-after($sValue, 'px')"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="concat(substring($sBeforePx, 1, $nLengthBeforeInteger), string($nValueIn), 'in', $sRest)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$sValue"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="altova:GetCharCountOfIntegerAtEndOfString">
<xsl:param name="sText"/>
<xsl:variable name="sLen" select="string-length($sText)"/>
<xsl:variable name="cLast" select="substring($sText, $sLen)"/>
<xsl:choose>
<xsl:when test="number($cLast) >= 0 and number($cLast) <= 9">
<xsl:variable name="nResultOfRest">
<xsl:call-template name="altova:GetCharCountOfIntegerAtEndOfString">
<xsl:with-param name="sText" select="substring($sText, 1, $sLen - 1)"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$nResultOfRest + 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>0</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Does anyone know why this is happening?
I have multiple PDFs with the same layout, so if I need to upgrade to fop-2.3 do I have to make this change to all of my PDFs?
EDIT- 1. Thank you for the comments and the answer. Sorry it took a while to reply back, as I was working on getting approvals to post this xslt.
2. I edited the xslt as it was too big to adhere to the word limit of this post. But it still has all the important parts like beginning of the PDF body etc.
Sorry, but the best way to work out why something is different between different versions of the same software is to look through the release notes for the releases since your older version.
FOP has release notes on its website. When I was confirming that, I found this at https://xmlgraphics.apache.org/fop/1.0/changes_1.0.html, which might be what you are looking for:
Allowing non-zero borders and padding on page regions when relaxed validation is turned on. Committed by LF.
If that is the cause, then the solution would be to remove the margin-top from the fo:simple-page-master. Otherwise, there's plenty more release notes for you to look through, I'm afraid.
Here is snippet of my xsl:
<fo:table-row height="27.8mm">
<fo:table-cell border-bottom="0.2mm solid" number-columns-spanned="2">
<fo:table border="0px solid"
border-collapse="collapse"
table-layout="fixed"
width="100%"
height="100%">
<fo:table-column column-width="110mm"/>
<fo:table-body>
<fo:table-row height="27.8mm">
<fo:table-cell border-bottom="0.2mm solid" height="28mm">
<xsl:call-template name="LabelTemplate">
<xsl:with-param name="name" select="'REFERENCE'"/>
</xsl:call-template>
<xsl:call-template name="ReferenceTemplate">
<xsl:with-param name="First" select="First"/>
<xsl:with-param name="Second" select="Second"/>
<xsl:with-param name="eNo" select="eNo"/>
</xsl:call-template>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:table-cell>
</fo:table-row>
When using inline container inside ReferenceTemplate nothing is displayed.
<xsl:template name="ReferenceTemplate">
<xsl:param name="First"/>
<xsl:param name="Second"/>
<xsl:param name="eNo"/>
<xsl:param name="size" select="'22pt'"/>
<xsl:param name="left" select="'5pt'"/>
<xsl:param name="top" select="'15px'"/>
<xsl:param name="text-indent" select="'5px'"/>
<fo:block-container
position="absolute"
top="{$top}" left="{$left}" right="5pt"
width="auto"
border="0px solid">
<fo:inline-container vertical-align="top" inline-progression-dimension="49.9%">
<fo:block><xsl:value-of select="$Second"/></fo:block>
</fo:inline-container>
<fo:inline-container vertical-align="top" inline-progression-dimension="49.9%">
<fo:block><xsl:value-of select="$First"/></fo:block>
</fo:inline-container>
</fo:block-container>
</xsl:template>
When using this sample instead of inline container content is displayed.
<fo:block text-align-last="justify">
<xsl:value-of select="$Second"/>
<fo:leader leader-pattern="space" />
<xsl:value-of select="$First"/>
</fo:block>
I think you cannot embed an fo:inline-container into an fo:block-container.
See this reference for fo:block-container - fo:inline-container is not in the list of allowed children.
I have the following XML:
<Pattern name="Form" Date="12/18/2015 3:25 AM CST">
Swap_Conversion
<CurrentLocale />
<Patterns>
<Pattern name="Section">
Swap_Conversion
<Patterns>
<Pattern name="GroupResult" status="AUTH" inputType="19">
Ultrasound Duration
<Patterns>
<Pattern name="GridDTA">23350691</Pattern>
<Pattern name="GridDTA">56468381</Pattern>
<Pattern name="GridDTA">20218422</Pattern>
<Pattern name="GridDTA">21058661</Pattern>
<Pattern name="GridDTA">4156900</Pattern>
<Pattern name="GridDTA">20008930</Pattern>
<Pattern name="GridDTA">21197198</Pattern>
</Patterns>
<Patterns>
<Pattern name="GroupResult" status="AUTH" inputType="">
Ear Irrigation Solution
<Patterns />
<Patterns>
<Pattern name="CodedResult" status="AUTH" display="Ace Bandage :" taskAssayCode="23350691">2 inch</Pattern>
</Patterns>
</Pattern>
</Patterns>
<Patterns>
<Pattern name="GroupResult" status="AUTH" inputType="">
Frame Order Priority
<Patterns />
<Patterns>
<Pattern name="CodedResult" status="AUTH" display="Ace Bandage :" taskAssayCode="23350691">3 inch</Pattern>
</Patterns>
</Pattern>
</Patterns>
</Pattern>
</Patterns>
</Pattern>
</Patterns>
</Pattern
Currently I have the transpose which look something like:
But I want it to look something like:
Currently I had tried with which worked for transpose:
<xsl:choose>
<xsl:when test="$inputType='19'"
<xsl:variable name="groupNodeSet" select="Patterns/Pattern[#name='GroupResult']"/>
<xsl:for-each select="$groupNodeSet[position() <= ((last() + $tablecolumns - 1) div $tablecolumns)]">
<!-- loopCount indicates which table of the multiple tables that a grid control may be split into that we are currently generating-->
<xsl:variable name="loopCount" select="position()"/>
<fo:table border="1pt solid black">
<fo:table-column/>
<fo:table-column/>
<fo:table-column/>
<fo:table-body>
<fo:table-row>
<fo:table-cell border-width="thin">
<fo:block/>
</fo:table-cell>
<fo:table-cell>
<xsl:if test="$groupNodeSet[position()=((($loopCount - 1) * $tablecolumns) + 1)]">
<xsl:attribute name="border-width">
<xsl:text>thin</xsl:text>
</xsl:attribute>
</xsl:if>
<fo:block font-size="{$regularfontsize}" font-family="sans-serif" text-align="left" font-style="italic">
<xsl:value-of select="$groupNodeSet[position()=((($loopCount - 1) * $tablecolumns) + 1)]/text()"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<xsl:if test="$groupNodeSet[position()=((($loopCount - 1) * $tablecolumns) + 2)]">
<xsl:attribute name="border-width">
<xsl:text>thin</xsl:text>
</xsl:attribute>
</xsl:if>
<fo:block font-size="{$regularfontsize}" font-family="sans-serif" text-align="left" font-style="italic">
<xsl:value-of select="$groupNodeSet[position()=((($loopCount - 1) * $tablecolumns) + 2)]/text()"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
<xsl:for-each select="../../Patterns/Pattern[#name='GridDTA' and ../..//#taskAssayCode=text()]">
<xsl:variable name="taskassay">
<xsl:value-of select="node()"/>
</xsl:variable>
<fo:table-row>
<fo:table-cell border-width="thin">
<fo:block>
<xsl:value-of select="../..//Pattern/#display[../..//Pattern/#taskAssayCode=$taskassay]"/>
</fo:block>
</fo:table-cell>
<xsl:call-template name="GenerateGridTableCells">
<xsl:with-param name="count" select="1"/>
<xsl:with-param name="maxcount" select="$tablecolumns"/>
<xsl:with-param name="taskassay" select="$taskassay"/>
<xsl:with-param name="groupNodeSet" select="$groupNodeSet"/>
<xsl:with-param name="rowNumber" select="$loopCount"/>
</xsl:call-template>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</xsl:for-each>
</xsl:when>
</xsl:choose>
I have tried multiple approach for normal one (not the transpose) which isn't working for.
Can anyone help me in having the grid matrix without transpose for the above XML?
Since you're using XSLT 1.0, you're stuck with using Meunchian grouping (muenchian grouping, http://www.jenitennison.com/xslt/grouping/muenchian.html). Using XSLT 2.0 would have made it easier.
The version below can cope with a variations in the 'CodedResult' within each 'GroupResult'.
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:variable name="regularfontsize" select="'12pt'"/>
<xsl:output indent="yes" />
<xsl:key name="coded-results"
match="Pattern[#name = 'CodedResult'][#status = 'AUTH']"
use="#display" />
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:axf="http://www.antennahouse.com/names/XSL/Extensions">
<fo:layout-master-set>
<fo:simple-page-master master-name="a">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="a">
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates select="Pattern/Patterns/Pattern[#name = 'Section']/Patterns/Pattern" />
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:variable name="inputType" select="'19'" />
<xsl:template match="Pattern[#inputType = '19']">
<xsl:variable name="all-coded-results"
select="Patterns/Pattern[#inputType = '']/Patterns/Pattern[#name = 'CodedResult']
[count(. | key('coded-results', #display)[1]) = 1]" />
<fo:table border="1pt solid black">
<fo:table-column/>
<xsl:for-each
select="$all-coded-results">
<fo:table-column/>
</xsl:for-each>
<fo:table-body>
<fo:table-row>
<fo:table-cell />
<xsl:for-each
select="$all-coded-results">
<xsl:sort />
<fo:table-cell>
<fo:block>
<xsl:value-of select="#display" />
</fo:block>
</fo:table-cell>
</xsl:for-each>
</fo:table-row>
<xsl:apply-templates select="Patterns/Pattern[#name = 'GroupResult']">
<xsl:with-param name="all-coded-results" select="$all-coded-results" />
</xsl:apply-templates>
</fo:table-body>
</fo:table>
</xsl:template>
<xsl:template match="Pattern[#name = 'GroupResult'][#inputType = '']">
<xsl:param name="all-coded-results" />
<fo:table-row>
<fo:table-cell>
<fo:block>
<xsl:value-of select="normalize-space(text())" />
</fo:block>
</fo:table-cell>
<xsl:variable name="this-pattern" select="." />
<xsl:for-each
select="$all-coded-results">
<xsl:sort />
<xsl:variable name="this-result" select="."/>
<fo:table-cell>
<xsl:if test="$this-pattern/Patterns/Pattern[#display = $this-result/#display]">
<fo:block>
<xsl:value-of select="$this-pattern/Patterns/Pattern[#display = $this-result/#display]" />
</fo:block>
</xsl:if>
</fo:table-cell>
</xsl:for-each>
</fo:table-row>
</xsl:template>
</xsl:stylesheet>
I have the following code who calls a template :
<xsl:call-template name="LigneDonnee">
<xsl:with-param name="text">Les émissions de CO<fo:inline font-size="6pt">2</fo:inline> :</xsl:with-param>
<xsl:with-param name="value"><xsl:value-of select='InfoGenerale/EmissionCO2' /></xsl:with-param>
</xsl:call-template>
Which call the following template :
<xsl:template name="LigneDonnee">
<xsl:param name="text"/>
<xsl:param name="value"/>
<fo:table table-layout="fixed" width="9.5in" padding-bottom="6pt" padding-top="6pt">
<fo:table-column column-width="6.0in"/>
<fo:table-column column-width="1.70in"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block><xsl:value-of select="$text" disable-output-escaping="yes" /></fo:block>
</fo:table-cell>
<fo:table-cell text-align="right" vertical-align="middle">
<fo:block>
<xsl:if test="$value != ''">
<xsl:value-of select='translate(format-number($value, "### ### ### ##0.######"),".",",")' />
</xsl:if>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</xsl:template>
My problem is that the CO<fo:inline font-size="6pt">2</fo:inline> seems to be transformed to a mere CO2 by the <xsl:value-of select="$text" />.
How to avoid/circumvent?
You have to change the value-of to xsl:copy-of
Try:
<xsl:copy-of select="$text" />