XSL-FO XSL-T footer onthe bottom of the last page - pdf

I have an xsl file to generate a pdf. I want to put a footer on the bottom of the last page. I tryed something like this:
<?xml version="1.0" encoding="windows-1252"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="windows-1252"/>
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<page-sequence-master master-name="pages">
<repeatable-page-master-alternatives>
<conditional-page-master-reference page-position="last" master-reference="last-page"/>
<conditional-page-master-reference master-reference="other-page"/>
</repeatable-page-master-alternatives>
</page-sequence-master>
<fo:simple-page-master master-name="A4" page-width="210mm" page-height="297mm" margin-top="1cm" margin-bottom="1cm"
margin-left="1cm" margin-right="1cm">
<fo:region-body margin-top="90mm" margin-bottom="80mm"/>
<fo:region-before extent="90mm"/>
<fo:region-after extent="80mm"/>
<fo:region-start/>
<fo:region-end/>
</fo:simple-page-master>
</fo:layout-master-set>
<html>
<fo:page-sequence master-reference="A4">
<fo:static-content flow-name="xsl-region-before">
<fo:block>
header
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
body
</fo:flow>
<fo:static-content flow-name="xsl-region-after">
<fo:block>
footer
</fo:block>
</fo:static-content>
</fo:page-sequence>
</html>
</fo:root>
</xsl:template>
The Footer appears at the end of the body and not at the end of the page, i dont know how to do it.

Your extent value on fo:region-after is the same as the margin-bottom value on the fo:region-body. If you reduce the extent, then the fo:region-after won't extend all the way up to the bottom of the fo:region-body.
See, e.g., the FO and PDF for 'Adding page numbers (page-number)' example at http://www.antennahouse.com/antenna1/comprehensive-xsl-fo-tutorials-and-samples-collection/. The FO includes:
<fo:simple-page-master page-height="150mm" page-width="210mm" margin-top="10mm"
margin-left="20mm" margin-right="20mm" margin-bottom="10mm" master-name="PageMaster">
<fo:region-before extent="15mm" />
<fo:region-after extent="15mm" />
<fo:region-body margin-top="0mm" margin-left="0mm" margin-right="0mm" margin-bottom="20mm" />
</fo:simple-page-master>
You can see that here there's a 5mm difference between the extent and the margin-bottom.

Related

Why is it not OK to put a xsl:value-of into a fo:block?

I have the following XSL file:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output media-type="text" omit-xml-declaration="yes"/>
<xsl:template match="root/branch">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="simple"
page-height="29.7cm"
page-width="21cm"
margin-top="1cm"
margin-bottom="2cm"
margin-left="2.5cm"
margin-right="2.5cm">
<fo:region-body margin-top="3cm"/>
<fo:region-before extent="3cm"/>
<fo:region-after extent="1.5cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simple">
<fo:flow flow-name="xsl-region-body">
<fo:block font-size="12pt"
font-family="sans-serif"
line-height="15pt"
space-after.optimum="3pt"
text-align="justify">
<xsl:value-of select="branch/greenLeave"/>
<xsl:value-of select="branch/yellowLeave"/>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
When I open it in IDEA IntelliJ, I get the following error message:
Does anybody know what is wrong here? I cannot find a plausible explanation.
Seems like the XSD for FOP which I downloaded from https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk/fop/src/foschema/fop.xsd lacked support for nested XSL-T statements.
As a workaround, I manually added a
<any processContent="skip"/>
to that XSD file at the right place.

We are printing images to a pdf using XSL fo. our aim is to print them in row wise but those are printing in column wise. Any suggestions please

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo" xml:space="preserve">
<xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>
<xsl:template match="assets">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="one" page-width="216mm" page-height="279mm" margin-top="10mm" margin-bottom="5mm" margin-left="10mm" margin-right="10mm">
<fo:region-body column-count="5" margin-top="1cm" margin-bottom="1cm"/>
<fo:region-before extent="1cm"/>
<fo:region-after extent="1cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="one">
<fo:static-content flow-name="xsl-region-before">
<fo:table table-layout="fixed" width="100%" font-size="16pt" text-align="center">
<fo:table-column column-width="proportional-column-width(1)"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block>
<xsl:value-of select="title"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
<!--footer-->
<fo:static-content flow-name="xsl-region-after">
<fo:block font-size="8pt" font-family="Arial" text-align="left">All rights reserved.</fo:block>
<fo:block font-family="Arial" font-size="8pt" text-align="right">Page <fo:page-number/>
</fo:block>
</fo:static-content>
<!-- body -->
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates select="assetExport"/>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:variable name="width" select="#displayValue"/>
<xsl:template match="assetExport">
<fo:block-container border-color="#D3D3D3" border-style="solid" border-width=".8px" margin-top="4mm" keep-together.within-column="always" width="36mm" height="56mm" scaling="uniform">
<xsl:apply-templates select="thumbnail"/>
<xsl:apply-templates select="metadata"/>
</fo:block-container>
</xsl:template>
<xsl:template match="metadata">
<xsl:apply-templates select="property"/>
</xsl:template>
<!-- Render the images -->
<xsl:template match="thumbnail">
<xsl:variable name="src" select="."/>
<xsl:choose>
<xsl:when test="$src = ''">
<fo:block-container>
<fo:block width="30mm" height="40mm" font-weight="bold" font-size="12pt" text-indent="5mm" margin-top="3mm" margin-bottom="2mm" margin-left="2mm" margin-right="2mm">
<xsl:text width="30mm" height="40mm">No Preview available</xsl:text>
</fo:block>
</fo:block-container>
</xsl:when>
<xsl:otherwise>
<fo:block margin-left="2mm" margin-right="2mm" margin-top="0mm">
<fo:external-graphic src="url(file:///{$src})" width="32mm" text-align="center" display-align="center" content-width="scale-to-fit" height="32mm" content-height="scale-to-fit" scaling="uniform"/>
</fo:block>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Render the metadata WITH Prompt -->
<xsl:template match="property">
<xsl:choose>
<xsl:when test="#prompt = 'Expiration Date'">
<fo:block margin-left="2mm" wrap-option="wrap" width="34mm" height="30mm" font-family="Arial" font-size="8pt" color="black">
<xsl:value-of select="(concat('Expiration Date: ',substring(child::property-value/attribute::displayValue,0,11)))"/>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:block margin-left="2mm" wrap-option="wrap" width="34mm" height="30mm" font-family="Arial" font-size="8pt" color="black">
<xsl:value-of select="attribute::prompt"/>
<xsl:text> : </xsl:text>
<xsl:value-of select="child::property-value/attribute::displayValue"/>
</fo:block>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

How to convert XSL To XSLT (in order to eventually convert to pdf)

i have an XML file that i am trying to convert to PDF.
i have an xsl file, but when i convert it to PDF it does not show it properly and the styling is not ok on the converted PDF
i've been told that in order to convert to PDF i need to use XSLT and not XSL.
i didn't find any converter or a guide on how to convert the XSL to XSLT.
Hopefuly someone here knows?
Many Thanks!
the converting itself to PDF is done with Magic XPI (Integration Software)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template name="RestOfWorldPdf">
<xsl:param name="barcode_url" />
<xsl:param name="images_dir" />
<fo:block-container break-before="page"
border-style="solid"
border-width="1px"
border-collapse="collapse"
font-family="sans-serif"
top="0px"
left="0px"
width="270px"
height="405px">
<!-- Logo-->
<fo:block-container absolute-position="absolute"
top="0px"
left="0px"
width="91px"
height="49px"
border-collapse="collapse"
border-right-width="1px"
border-right-style="solid"
text-align="center">
<fo:block>
<fo:external-graphic src="url('logo.jpg')"
content-height="46px"/>
</fo:block>
</fo:block-container>
<!-- Market & Transport Type -->
<fo:block-container
absolute-position="absolute"
top="0px"
left="93px"
height="23px"
width="111px">
<fo:block font-weight="bold"
font-size="14pt"
text-align="left"
padding-top="2px">
<fo:inline padding-left="1px">
<xsl:value-of select="../consignmentLabelData/marketDisplay"/>
</fo:inline>
<xsl:text> / </xsl:text>
<fo:inline>
<xsl:value-of select="../consignmentLabelData/transportDisplay" />
</fo:inline>
</fo:block>
</fo:block-container>

Using FOP to pull pages from an A4 PDF and create a A3 PDF

Im hoping someone can help me.
At the moment I create A4 Documents using FOP and XSLT. I have been asked to take these A4 (portrait) pages and then stitch them into an A3 booklet. So for example I have a 4 page A4 document which I need to convert into a 2 sided A3 booklet with the ability to order the first side using page 4 and 1 (side by side) and then the other side to be page 2 and 3.
I have looked at PDFBOX to see if it can do this but have had no success.
Does anyone have any ideas of how I could get the outcome that I need?
All help is appreciated!
You can do that with FOP if you wish and if you install the PDF Images Plug-In for FOP
<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="a3" margin-right="0mm" margin-left="0mm" margin-bottom="0mm" margin-top="0mm" page-width="42cm" page-height="29.7cm">
<fo:region-body margin-left="0mm" margin-top="0mm" margin-bottom="0mm" margin-right="0mm"/>
</fo:simple-page-master>
<fo:page-sequence-master master-name="a3n">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference master-reference="a3" page-position="any"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="a3n">
<fo:flow flow-name="xsl-region-body">
<fo:block-container height="29.7cm" width="20.9cm" top="0mm" left="0mm" position="absolute">
<fo:block>
<fo:external-graphic content-height="29.7cm" content-width="21cm" height="29.7cm" width="21cm" src="yourpathdoc.pdf#page=2"/>
</fo:block>
</fo:block-container>
<fo:block-container height="29.7cm" width="20.9cm" top="0mm" left="209mm" position="absolute">
<fo:block>
<fo:external-graphic content-height="29.7cm" content-width="21cm" height="29.7cm" width="21cm" src="yourpathdoc.pdf#page=3"/>
</fo:block>
</fo:block-container>
<fo:block-container>
<fo:block font-size="0.1pt" page-break-after="always" break-after="page"> </fo:block>
</fo:block-container>
<fo:block-container height="29.7cm" width="20.9cm" top="0mm" left="0mm" position="absolute">
<fo:block>
<fo:external-graphic content-height="29.7cm" content-width="21cm" height="29.7cm" width="21cm" src="yourpathdoc.pdf#page=4"/>
</fo:block>
</fo:block-container>
<fo:block-container height="29.7cm" width="20.9cm" top="0mm" left="209mm" position="absolute">
<fo:block>
<fo:external-graphic content-height="29.7cm" content-width="21cm" height="29.7cm" width="21cm" src="yourpathdoc.pdf#page=1"/>
</fo:block>
</fo:block-container>
</fo:flow>
</fo:page-sequence>
</fo:root>
Edit
In case you want it portrait for easier printing, simply switch the page-width and page-height of the simple-page-master and replace the four block-container lines containing the position="absolute" with
<fo:block-container height="29.7cm" width="21cm" top="0mm" left="0mm" position="absolute" reference-orientation="270">
...
<fo:block-container height="29.7cm" width="21cm" top="210mm" left="0mm" position="absolute" reference-orientation="270">
...
<fo:block-container height="29.7cm" width="21cm" top="0mm" left="0mm" position="absolute" reference-orientation="270">
...
<fo:block-container height="29.7cm" width="21cm" top="210mm" left="0mm" position="absolute" reference-orientation="270">
and if you have more than two pages don't forget to insert the
<fo:block-container>
<fo:block font-size="0.1pt" page-break-after="always" break-after="page"> </fo:block>
</fo:block-container>
everywhere inbetween (after every second image)

How to set a color in xslt once for all fields

Can I set a variable or something to lets say "red" once and when i want some font to be red i just call that variable? that way i can edit the color of all specified text with ease for future possibilities. I'm new to xslt and appreciate any help. thank you.
Edit: adding some code with what i would want.
<?xml version="1.0" encoding="utf-8"?><xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<!--Probably declare the variable here-->
<!--Like <variable=outputcolor value="red" -->
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="A4-portrait"
page-height="29.7cm" page-width="21.0cm" margin="2cm">
<fo:region-body />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4-portrait">
<fo:flow flow-name="xsl-region-body" font-family="Helvetica"
font-size="6pt">
<fo:block font-size="8pt" text-indent="5pt">
<fo:inline font-weight="bold"><xsl:text>Application Summary</xsl:text></fo:inline>
<!--Here i would like to make red a variable that i could possibly changed -->
<!--like fo:inline color="{outputcolor}"-->
<fo:inline color="red">
<xsl:value-of select="businessInfo/appSum" />
</fo:inline>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
Using an attribute-set is an option worth exploring. Another option is to do what you started to do:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<!--Probably declare the variable here-->
<xsl:variable name="outputcolor" select="'red'" />
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="A4-portrait"
page-height="29.7cm" page-width="21.0cm" margin="2cm">
<fo:region-body />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4-portrait">
<fo:flow flow-name="xsl-region-body" font-family="Helvetica"
font-size="6pt">
<fo:block font-size="8pt" text-indent="5pt">
<fo:inline font-weight="bold"><xsl:text>Application Summary</xsl:text></fo:inline>
<!--Here i would like to make red a variable that i could possibly changed -->
<fo:inline color="{$outputcolor}">
<xsl:value-of select="businessInfo/appSum" />
</fo:inline>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
Note that declaring the variable at the top level of the template limits its scope to that template only. You can declare global variables (at the top level of the stylesheet, outside of any template) to make them available anywhere in the stylesheet.
You can define a named attribute set as a direct child of xsl:stylesheet, containing the attributes you want to reuse:
<xsl:attribute-set name="colouredText">
<xsl:attribute name="color">red</xsl:attribute>
<!-- you can set other attributes too: font-weight, font-style, ... -->
</xsl:attribute-set>
and then use it when creating elements with xsl:copy, xsl:element or with a literal result element:
<xsl:copy use-attribute-sets="colouredText">
...
</xsl:copy>
<xsl:element name="fo:inline" use-attribute-sets="colouredText">
...
</xsl:element>
<fo:inline xsl:use-attribute-sets="colouredText">
...
</fo:inline>
If the output requirements change ("Besides being red, important info must be bold also" / "Forget the color, just made them italic" / "Try using Comic Sans") you only need to adjust the attribute definitions inside the attribute-set, without having to modify the templates where these "styles" are applied.
The value of the xsl:use-attribute-sets attribute is a whitespace-separated list of attribute set names:
<xsl:attribute-set name="spacedText">
<xsl:attribute name="space-before">12pt</xsl:attribute>
<xsl:attribute name="space-after">12pt</xsl:attribute>
</xsl:attribute-set>
...
<fo:block xsl:use-attribute-sets="colouredText spacedText">
This block is both coloured and spaced!
</fo:block>
An attribute set can in turn refer to other sets:
<xsl:attribute-set name="colouredTitle" use-attribute-sets="colouredText">
<xsl:attribute name="font-size">16pt</xsl:attribute>
<xsl:attribute name="text-align">center</xsl:attribute>
</xsl:attribute-set>
The linked section of the XSL 1.0 specifications (or the corresponding section of the XSL 2.0 specifications) provides further information about how attribute sets can be extended and merged.