source: ether_eccad/trunk/ECCAD_INTERFACE/WEB-INF/src/org/medias/eccad/metier/TransformXML.java @ 68

Last change on this file since 68 was 68, checked in by cbipsl, 14 years ago

commit v1 eccad

  • Property svn:executable set to *
File size: 1.1 KB
Line 
1package org.medias.eccad.metier;
2
3
4import javax.xml.transform.Source;
5import javax.xml.transform.Transformer;
6import javax.xml.transform.TransformerFactory;
7import javax.xml.transform.stream.StreamSource;
8import javax.xml.transform.stream.StreamResult;
9import java.io.*;
10
11public class TransformXML {
12
13    /**
14     * Performs an XSLT transformation
15     */
16    public String transformation(String xmlContent, String transformeur) throws Exception {
17
18
19        File xsltFile = new File(transformeur);
20
21        // JAXP reads data using the Source interface
22        Source xmlSource = new StreamSource(new StringReader(xmlContent));
23        Source xsltSource = new StreamSource(xsltFile);
24
25        // the factory pattern supports different XSLT processors
26        TransformerFactory transFact =
27                TransformerFactory.newInstance();
28        Transformer trans = transFact.newTransformer(xsltSource);
29
30        StringWriter sortie = new StringWriter();
31       
32        trans.transform(xmlSource, new StreamResult(sortie));
33       
34        return sortie.toString();
35    }
36}
Note: See TracBrowser for help on using the repository browser.