Bonjour,
je fais la conversion de xml en pdf avec fop du coup :
1- je génère un fichier xml
2- j'ai un fichier xsl de transformation
mais dès que mon fichier xml contient des données avec des caractères comme
"Services d'échanges de données fixes" la transformation xsl échoue avec l'exception :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
SEVERE: javax.xml.transform.TransformerException: java.io.UTFDataFormatException: Invalid byte 2 of 3-byte UTF-8 sequence.
je veux savoir si le problème vient de :
1- mon code java de transformation
2- ou mon fichier xsl

le code java est comme suivant:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
	public static boolean generatePDF(HttpServletResponse response, Object dataToSerialize, XStream xstream, String xslFilePath,String xmlFilePath) {
 
		logger.info("begin generatePDF");
 
		//TODO delete later :DEBUG : affiche dans System.out le résultat de la sérialisation
		xstream.toXML(dataToSerialize, System.out);
		boolean success = true;
 
		try {
 
			File xmlfile = new File(xmlFilePath);
 
			//File xsltfile = new File(xslFilePath);
			FileOutputStream fos = new FileOutputStream(xmlfile);
 
			// DEBUG : affiche dans System.out le résultat de la sérialisation
			xstream.toXML(dataToSerialize,fos);
 
			logger.info("DEBUG 1111111111111");
 
 
 
			logger.info("DEBUG 22222222222222");		
			// read xsl file into xslInputStream
			File xslFile = new File(xslFilePath);
 
			InputStream xslInputStream = new FileInputStream(xslFile);
			//TODO to test to reslove caractères problem
			//InputStream xslInputStream = new ByteArrayInputStream(xslFile.toString().getBytes("UTF-8"));
 
			// create output stream
			ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
 
 
			logger.info("DEBUG 444444444444");
 
			// create pdf driver
			Driver driver = new Driver();
			driver.setLogger(new ConsoleLogger(ConsoleLogger.LEVEL_INFO));
			driver.setRenderer(Driver.RENDER_PDF);
			driver.setOutputStream(outputStream);
 
			logger.info("DEBUG 5555555555555");
 
			// encapsulate objects...
			//Source xml = new StreamSource(xmlInputStream);
			Source xsl = new StreamSource(xslInputStream);
		//	Result res = new SAXResult(driver.getContentHandler());
 
//			 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(driver.getContentHandler());
			try {
				logger.info("DEBUG 6666666666666");
				// transform xml with xsl
				Transformer transformer = TransformerFactory.newInstance().newTransformer(xsl);
				transformer.setParameter("versionParam", "2.0");
 
				// Start XSLT transformation and FOP processing
				transformer.transform(src, res);
				logger.info("DEBUG 6.1");
				// set response with transformed data
				response.setContentType("application/pdf");
				response.setHeader("Content-Disposition", "attachment; filename=contrats.pdf");
 
				logger.info("DEBUG 6.2");
 
				response.setContentLength(outputStream.size());
				response.getOutputStream().write(outputStream.toByteArray());
 
				logger.info("DEBUG 6.3");
 
				response.getOutputStream().flush();
				response.getOutputStream().close();
			}
			finally {
				logger.info("DEBUG 77777777777");
				//xmlInputStream.close();
				xslInputStream.close();
				outputStream.close();
			}
 
		}
		catch (Exception e) {
			success = false;
			logger.severe(e.toString());
		}
 
		logger.info("end generatePDF");
		return success;
	}
le fichier xsl est déclaré au début comme suivant:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xml.apache.org/fop/extensions" xmlns:xi="http://www.w3.org/2001/Xinclude">
	<xsl:output method="xml" encoding="UTF-8" indent="yes"></xsl:output>
et utilisant fop pour la transformation mon fichier xsl contient des balises de ce genre:
<fo:block text-align="left" border="1px solid black" margin-left="1cm" margin-right="1cm">
<xsl:apply-templates select="contractsImpression/contracts"/>
</fo:block>