Bonjour, voila mon code java permettant de créer une page html via un XML et mis en forme par un XSL.

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
public class Main {
	public static void main(String[] args) {
		try {
			System.out.println("Go");		
			//construction du fichier XML		DocumentBuilderFactoryfabrique=DocumentBuilderFactory.newInstance();		
			fabrique.setNamespaceAware(true);			
			// fabrique.setValidation(true);
			DocumentBuilder analyseur =fabrique.newDocumentBuilder();
 
			//création du fichier XML
			Document doc=analyseur.parse(newFile("FR-FR-Form270207-4-1.xml"));
			DOMSource sourceXML = new DOMSource(doc);
 
			//Création du fichier XSL
			doc = analyseur.parse(new File("test.xsl"));
			DOMSource sourceXSL = new DOMSource(doc);
 
			TransformerFactory trFact = TransformerFactory.newInstance();
			Transformer transformeur = trFact.newTransformer(sourceXSL);
			transformeur.setOutputProperty(OutputKeys.METHOD, "html");
			transformeur.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
			transformeur.setOutputProperty(OutputKeys.INDENT, "yes");
 
			//transformeur.setParameter("num", "6");
 
			File oFic = new File("resultat.vm");
			FileOutputStream fos = new FileOutputStream(oFic);
 
			if (fos != null) {
				Result sortie = new StreamResult(fos);
				transformeur.transform(sourceXML, sortie);
			}
 
			fos.flush();
			fos.close();
			System.out.println("XSL transf done");
 
 
			Velocity.init();
			VelocityContext context = new VelocityContext();
			context.put( "date", new DateHelper());
			Template template = Velocity.getTemplate("resultat.vm");
 
			FileWriter fw = new FileWriter("result.html");
 
			template.merge( context, fw );
			fw.close();
			System.out.println("Velocity transf done");					
		} catch (Throwable t) {
			t.printStackTrace();
		}
	}
 
}
Je souhaite créer à partir de ce XML plusieurs page HTML, mais ne sait pas comment faire.

Merci d'avance