1 Reply Latest reply on Nov 13, 2010 7:32 AM by sud201449

    Trouble implementing XSLT in seam application

    tvraghavan

      We are implementing a generic dynamic view generation layer that can render the output using XSLT. We extract the SOAP body from the soap response, apply XSLT to generate template based html output.


      The same implementation works fine using a simple JSP/Servlet implementation.


      But when we implement the same logic within seam, we get an exception



      "
      2010-09-28 00:18:27,709 ERROR [STDERR] (http-0.0.0.0-8080-4) [Fatal Error] :-1:-1: Premature end of file.
      2010-09-28 00:18:27,711 ERROR [STDERR] (http-0.0.0.0-8080-4) javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerException: org.xml.sax.SAXParseException: Premature end of file.
      2010-09-28 00:18:27,712 ERROR [STDERR] (http-0.0.0.0-8080-4)      at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:936)
      2010-09-28 00:18:27,712 ERROR [STDERR] (http-0.0.0.0-8080-4)      at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:774)
      
      "



      Code snippet




          private String processXML() throws IOException {
                StringWriter out = new StringWriter();
                if(this.xmlinputString != null && this.xsltemplate != null)
                try {
                     TransformerFactory tFactory = TransformerFactory.newInstance();
      
                     Transformer transformer = tFactory.newTransformer(new StreamSource(
                               new StringReader(getXsltemplate())));
      
                     transformer.transform(new StreamSource(new StringReader(
                               getXmlinputString())), new StreamResult(out));
      
                } catch(Exception e) {
                     e.printStackTrace();
                     throw new IOException(e);
                }
                      System.out.println(out.toString());
                return (out.toString());
      
           }
      









        • 1. Re: Trouble implementing XSLT in seam application
          sud201449

          Hi Raghav,
                   I have tried the same and able to generate dynamic html




          public static void translate(String xmlFile, String xslFileName,StreamResult result) throws Exception
          {                         
                  try
                  { 
                  File xmlFile = new File(xmlFile);
              File xsltFile = new File(xslFileName);

              // JAXP reads data using the Source interface
              Source xmlSource = new StreamSource(xmlFile);
              Source xsltSource = new StreamSource(xsltFile);

              // the factory pattern supports different XSLT processors
              TransformerFactory transFact =
                      TransformerFactory.newInstance();
              Transformer trans = transFact.newTransformer(xsltSource);

               trans.transform(xmlSource, result);
             
                  }
                  catch (Exception e)
                  {
                    e.printStackTrace();
                                 
                  }
                 
          }