[ERROR]:org.apache.fop.fo.ValidationException XSL XML FOP
Bonjour à tous,
Je suis novice dans l'utilisation de FOP et même au concept XML/XSLT/XSL-FO, et je cherche à générer un PDF à partir d'un fichier XML.
Pour ce qui est de la génération du fichier XML, je n'ai pas de soucis (j'utilise XMLEncoder pour créer mon XML à partir de bean Java).
Exemple de XML:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.6.0_18" class="java.beans.XMLDecoder">
<object class="java.util.ArrayList">
<void method="add">
<object class="com.atosorigin.cacc.ir.services.dto.DisplayTransactionDto">
<void property="blablatId">
<string>toto</string>
</void>
<void property="blablaRef">
<string>000</string>
</void>
<void property="carID">
<string>015</string>
</void>
<void property="carNumb">
<string>001</string>
</void>
<void property="currency">
<string>EUR</string>
</void>
<void property="currentAmount">
<string>282,50</string>
</void>
<void property="datePurchase">
<object class="java.sql.Timestamp">
<long>1310018400000</long>
</object>
</void>
<void property="payment">
<string>Cheque</string>
</void>
</object>
</void>
</object>
</java> |
Un fois la génération faite, je me suis lancé dans la construction du XSL pour pouvoir créer mon Objet XSL-FO:
J'ai commencé par les bases et je suis bloqué sur cette erreur...
Code:
1 2 3 4
|
javax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException:
"{http://www.w3.org/1999/XSL/Format}page-sequence"
is not a valid child of "fo:layout-master-set"! (No context info available) |
Voici mon XSL:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
<?xml version="1.0"?>
<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"/>
<xsl:template match="/java/object/void/object/void" >
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:page-sequence master-reference="A4">
<fo:table-and-caption>
<fo:table>
</fo:table>
</fo:table-and-caption>
</fo:page-sequence>
</fo:layout-master-set>
</fo:root>
</xsl:template>
</xsl:stylesheet> |
Pour info:
voici mon code java pour générer le Stream pour la création du pdf:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
// Setup input and output files
File xmlfile = new File("testXML.xml");
File xsltfile = new File("TestXSL.xsl");
System.out.println("Input: XML (" + xmlfile + ")");
System.out.println("Stylesheet: " + xsltfile);
System.out.println("Transforming...");
// configure fopFactory as desired
FopFactory fopFactory = FopFactory.newInstance();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
// configure foUserAgent as desired
// ByteArrayOutputStream baosTestXml = new ByteArrayOutputStream();
// Construct fop with desired output format
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, baos);
// Setup XSLT
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(xsltfile));
// Set the value of a <param> in the stylesheet
transformer.setParameter("versionParam", "2.0");
// Setup input for XSLT transformation
Source src = new StreamSource(xmlfile);
// Resulting SAX events (the generated FO) must be piped through to FOP
Result res = new SAXResult(fop.getDefaultHandler());
// Start XSLT transformation and FOP processing
transformer.transform(src, res); |
Merci pour votre aide ;)