Hello,
Using Java25, FOP 2.11, Windows11.
This way be related to issue FOP-3275.
We directly generate FO files from the UI layer of our application. And use
FOP to transform these into PDF files.
We are in the process of moving to Java 25. Since this move the transform
is no longer working. We get the error : FWK005 parse may not be called
while parsing.
To do this we call the transformation like this :
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
// 5️⃣ Set up input (FO file) and output (SAXResult to FOP)
StreamSource src = new StreamSource(foFile);
SAXResult res = new SAXResult(fop.getDefaultHandler());
// 6️⃣ Transform the FO to PDF
transformer.transform(src, res);
However, we have found the if we wrap our FO (fopInvoice2.xml) file into an
XSL file (fopInvoice3.xml) and use a dummy xml for the transform it works.
Source xslSource = new StreamSource(reader);
String xml = """
<doc></doc>
""";
Source xmlSource = new StreamSource(new StringReader(xml));
Transformer transformer = tf.newTransformer(xslSource);
// 5) Pipe the XSLT result directly into FOP as SAX events
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(xmlSource, res);
This approach seems couter-intuitive as adding a transformation layer
reduces the transformation imbrication.
Are we doing something wrong?
Kind regards,
Daniel
<?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="A4" page-width="210mm" page-height="297mm" margin="20mm">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4">
<fo:flow flow-name="xsl-region-body">
<fo:block font-family="sans-serif" font-size="12pt">
Hello, Ian! This PDF was built from XML+XSLT in memory.
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="no"/>
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="A4" page-width="210mm" page-height="297mm" margin="20mm">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4">
<fo:flow flow-name="xsl-region-body">
<fo:block font-family="sans-serif" font-size="12pt">
Hello, Ian! This PDF was built from XML+XSLT in memory.
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>