Bonjour,
Je dois appliquer une XSL (A) a une XSL (B) pour générer une XSL (C).
Seulement j'ai une erreur qui apparait !
Voici mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part (Emplacement inconnu de l'erreur)org.xml.sax.SAXException: Un DOM ne peut posséder plusieurs racines !
L'erreur apparait a la ligne : doc = (Document) resultat.getNode();
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 public static void main(String[] args) { String xslInput = "http://localhost:8080/c/journal/get_template?templateId=NEWS-ITEM-TEMPLATE"; String xslTransformer = "http://localhost:8080/XSLtoXSL.xsl"; try { Document XSLInputSource = getFileDocument(xslInput); Document XSLTransformer = getFileDocument(xslTransformer); Document doc = getTransformResult(XSLInputSource,XSLTransformer); writeXmlFile(doc,"XSL.xsl"); } catch (IOException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } } public static Document getTransformResult(Document XSLInput, Document XSLTransformer) { DOMResult resultat = new DOMResult(); Document doc = null; try { TransformerFactory fabrique = TransformerFactory.newInstance(); Transformer transformer = fabrique.newTransformer(new DOMSource(XSLInput)); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(new DOMSource(XSLTransformer), resultat); doc = (Document) resultat.getNode(); } catch (Exception e) { e.printStackTrace(); } return doc; } public static Document getFileDocument(String file) throws IOException, ParserConfigurationException, SAXException, URISyntaxException { Document InputDocument = null; URL fileUrl = new URL(file); URLConnection FileURLConnection = fileUrl.openConnection ( ) ; HttpURLConnection httpFileConnection = (HttpURLConnection) FileURLConnection; int responseCodeInput = httpFileConnection.getResponseCode () ; if ( responseCodeInput != HttpURLConnection.HTTP_OK ) { System.out.println("NOT HTTP OK"); } else { InputStream streamInput = httpFileConnection.getInputStream () ; DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance(); fabrique.setNamespaceAware(true); DocumentBuilder constructeur = fabrique.newDocumentBuilder(); InputDocument = constructeur.parse(streamInput); //source = new DOMSource(InputDocument); } return InputDocument; }
J'ai bien sur vérifié les URL de mes 2 fichiers d'entrée, qui sont bons...
Help !
Partager