Java XML Transform transformar(String xmlOrigen, String xslOrigen)

Here you can find the source of transformar(String xmlOrigen, String xslOrigen)

Description

transformar

License

Open Source License

Declaration

public static String transformar(String xmlOrigen, String xslOrigen) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;

public class Main {
    public static String transformar(String xmlOrigen, String xslOrigen) throws Exception {
        //System.out.println("xmlOrigen:"+xmlOrigen);

        InputStream is = new ByteArrayInputStream(xmlOrigen.getBytes("UTF-8"));

        Source xmlSource = new StreamSource(is);
        Source xsltSource = new StreamSource(new File(xslOrigen));

        StringWriter cadenaSalida = new StringWriter();

        Result bufferResultado = new StreamResult(cadenaSalida);

        TransformerFactory factoriaTrans = TransformerFactory.newInstance();
        Transformer transformador = factoriaTrans.newTransformer(xsltSource);

        transformador.transform(xmlSource, bufferResultado);

        return cadenaSalida.toString();
    }//from  w ww . java2 s.  c  o  m
}

Related

  1. transform(String xmlInputFile, String xsltInputFile, OutputStream outputStream)
  2. transform(String xmlInURI, String xslInURI)
  3. transform(String xmlsource, File xsltfile)
  4. transform(String xslSource, Node original)
  5. transform(Transformer transformer, Node element)
  6. transformer()
  7. transformerExceptionMsg(TransformerException ex, Node contextNode, String str)
  8. transformerFactory()
  9. transformFile(Source stylesheetFile, File input, File output)