Venus Fugerit Doc sample showing the new custom XSL feature for mod-fop
This is a sample project configured using fj-doc-maven-plugin init plugin.
This project is part of a series of mini tutorial on Venus Fugerit Doc, here you can find the other tutorials.
- JDK 8+ (*)
- Maven 3.8+
(*) Currently FOP not working on JDK 25, See bug JDK-8368356.
This project was created with Venus Maven plugin
mvn org.fugerit.java:fj-doc-maven-plugin:8.17.2:init \
-DgroupId=org.fugerit.java.demo \
-DartifactId=venus-sample-pdf-fop-xslt \
-Dextensions=base,freemarker,mod-fop \
-DaddJacoco=true \
-DaddJacoco=addFormatting=true \
-DwithCI=github \
-Dflavour=vanillaWe need to add the mod-fop-xslt-path attribute :
<info name="mod-fop-xslt-path">venus-sample-pdf-fop-xslt/fop-xslt/xslt-sample.xsl</info>Optionally set the mod-fop-xslt-debug attribute :
<info name="mod-fop-xslt-debug">true</info>In our document there are two tables. The second one is not fitting the page.
Our XSLT template :
<?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" encoding="UTF-8"/>
<!-- Identity template - copies everything as-is -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- Specific template for elements with id="end-element" -->
<xsl:template match="*[@id='end-element']">
<xsl:copy>
<!-- Copy existing attributes -->
<xsl:apply-templates select="@*"/>
<!-- Add the keep-together attribute -->
<xsl:attribute name="keep-together.within-page">always</xsl:attribute>
<!-- Copy child nodes -->
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>Will add the attribute keep-together.within-page to the resulting XSLT :
<xsl:attribute name="keep-together.within-page">always</xsl:attribute>