Skip to content

fugerit79/venus-sample-pdf-fop-xslt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

venus-sample-pdf-fop-xslt

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.

Keep a Changelog v1.1.0 badge Quality Gate Status Coverage License: MIT code of conduct

This project is part of a series of mini tutorial on Venus Fugerit Doc, here you can find the other tutorials.

Requirement

  • JDK 8+ (*)
  • Maven 3.8+

(*) Currently FOP not working on JDK 25, See bug JDK-8368356.

Project initialization

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=vanilla

Mod FOP XSLT Processing

We 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>

About

Venus Fugerit Doc sample showing the new custom XSL feature for mod-fop

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published