Examples of XSLTProcessor


Examples of org.apache.xalan.xslt.XSLTProcessor

* xerces for the serialization, xalan and bsf for the extension.
* @todo do everything via reflection to avoid compile problems ?
*/
class Xalan1Executor extends XalanExecutor {
    void execute() throws Exception {
        XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
        // need to quote otherwise it breaks because of "extra illegal tokens"
        processor.setStylesheetParam("output.dir", "'" + caller.toDir.getAbsolutePath() + "'");
        XSLTInputSource xml_src = new XSLTInputSource(caller.document);
        String system_id = caller.getStylesheetSystemId();
        XSLTInputSource xsl_src = new XSLTInputSource(system_id);
        OutputStream os = getOutputStream();
        XSLTResultTarget target = new XSLTResultTarget(os);
        processor.process( xml_src, xsl_src, target);
    }
View Full Code Here

Examples of org.apache.xalan.xslt.XSLTProcessor

     * When a new report has been generated, this consumer
     * applies the same stylesheet to the input XML document
     */
    public void onNewReport(File xmlReport)
        throws Exception{
        XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
       
        processor.process(new XSLTInputSource(xmlReport.toURL().toString()),
                          new XSLTInputSource(stylesheet),
                          new XSLTResultTarget(createNewReportOutput().getAbsolutePath()));
    }
View Full Code Here

Examples of org.apache.xalan.xslt.XSLTProcessor

{
  public static void main(String[] args)
    throws Exception
  {
    // Create an XSLT processor, returning an XSLTProcessor interface.
    XSLTProcessor processor = XSLTProcessorFactory.getProcessor();

    // Create a stylesheet using SAX.

    // Instantiate a Xerces SAX parser.
    SAXParser saxparser = new SAXParser();

    // Create an empty StylesheetRoot. The createStylesheetRoot(String baseURI) method is not
    // part of the XSLTProcessor interface, so must use the underlying XSLTEngineImpl object.
    // The baseURI is for resolving relative URIs. If null is sent, defaults to the current
    // directory.
    StylesheetRoot stylesheet = ((XSLTEngineImpl)processor).createStylesheetRoot(null);

    // Set up a StylesheetHandler (a SAX DocumentHandler) to receive events
    // as the Stylesheet is parsed.
    StylesheetHandler stylesheetHandler
      = new StylesheetHandler((XSLTEngineImpl)processor, stylesheet);

    // Set the StylesheetHandler to listen to SAX events from the SAX parser.
    saxparser.setDocumentHandler(stylesheetHandler);

    // Parse foo.xsl, sending SAX events to stylesheetHandler, which fills in the
    // StylesheetRoot object.
    saxparser.parse("foo.xsl");

    // Do a SAX-driven transform.

    // Reset the parser for a new parse.
    saxparser.reset();
    // Set the processor Stylesheet property, telling the processor which stylesheet to use.
    processor.setStylesheet(stylesheet);
    // Set the processor to act as a DocumentHandler, receiving SAX events from the
    // SAX parser.
    saxparser.setDocumentHandler(processor);
    // Set the SAX Parser lexical handler to the XSLTProcessor, so the SAX parser
    // can handle lexical events in the XML source, such as the occurrence of comment nodes.
    saxparser.setProperty("http://xml.org/sax/properties/lexical-handler", processor);
    // Set the processor to output the result to the screen.
    processor.setOutputStream(System.out);
    // Parse foo.xml, sending SAX events to the processor, which sends output
    // to a stream.
    saxparser.parse("foo.xml");
  }
View Full Code Here

Examples of org.apache.xalan.xslt.XSLTProcessor

    throws java.io.IOException,
           java.net.MalformedURLException,
           org.xml.sax.SAXException
  {
    // Use the XSLTProcessorFactory to create a processor.
    XSLTProcessor processor = XSLTProcessorFactory.getProcessor();

    // Compile the two stylesheets.
    StylesheetRoot stylesheet = processor.processStylesheet("foo.xsl");
    StylesheetRoot stylesheet2 = processor.processStylesheet("foo2.xsl");

    // Don't really need to set the processor Stylesheet property, since it's
    // still set from the 2nd processStylesheet, but it's good form....
    processor.setStylesheet(stylesheet2);

    // Get and set a DocumentHandler for final output.
    processor.setDocumentHandler(stylesheet2.getSAXSerializer(System.out));

    // Use the processor (which extends DocumentHandler) to instantiate the
    // XSLTResultTarget object for the first transform.
    XSLTResultTarget firstResult = new XSLTResultTarget(processor);
    // firstResult now functions as a SAX DocumentHandler.
View Full Code Here

Examples of org.apache.xalan.xslt.XSLTProcessor

    throws java.io.IOException,
           java.net.MalformedURLException,
           org.xml.sax.SAXException
  {
    // Create an XSLT processor.
    XSLTProcessor processor = XSLTProcessorFactory.getProcessor();

    // Create input source documents.
    XSLTInputSource xmlID = new XSLTInputSource("foo.xml");
    XSLTInputSource stylesheetID = new XSLTInputSource("foo.xsl");

    // Create a DOM Document node to attach the result nodes to.
    Document out = new org.apache.xerces.dom.DocumentImpl();
    XSLTResultTarget resultTarget = new XSLTResultTarget(out);

    // Process the source tree and produce the result tree.
    processor.process(xmlID, stylesheetID, resultTarget);

    // Use the FormatterToXML and TreeWalker to print the DOM to System.out
    // Note: Not yet sure how to get the Xerces Serializer to  handle
    // arbitrary nodes.
    FormatterToXML fl = new FormatterToXML(System.out);
View Full Code Here

Examples of org.apache.xalan.xslt.XSLTProcessor

      return;
    }

    // Have the XSLTProcessorFactory obtain a interface to a
    // new XSLTProcessor object.
    XSLTProcessor processor = XSLTProcessorFactory.getProcessor();

    // Set a param named "param1", that the stylesheet can obtain.
    processor.setStylesheetParam("param1", processor.createXString(args[0]));

    System.out.println("------------------");
    // Have the XSLTProcessor processor object transform "foo.xml" to
    // System.out, using the XSLT instructions found in "foo.xsl".
    processor.process(new XSLTInputSource("foo.xml"),
                      new XSLTInputSource("foo.xsl"),
                      new XSLTResultTarget(System.out));
    System.out.println("\n------------------");
  }
View Full Code Here

Examples of org.apache.xalan.xslt.XSLTProcessor

                     HttpServletResponse response)
    throws ServletException, IOException
  {
    try
    {
      XSLTProcessor processor = org.apache.xalan.xslt.XSLTProcessorFactory.getProcessor();
      process(processor, request, response);
    }
    catch (Exception e)
    {
    }
View Full Code Here

Examples of org.apache.xalan.xslt.XSLTProcessor

    // perform Transformation
    if ((xmlSource != null) && (xslSource != null))
    {
    try
    { // new try ... catch around ctor Update -sc
        XSLTProcessor xslprocessor = org.apache.xalan.xslt.XSLTProcessorFactory.getProcessor();
        {
          try
          {
            String contentType = null;
            if ((contentType = getContentType(xslprocessor.processStylesheet(xslSource))) != null)
              response.setContentType(contentType);
            xslprocessor.setQuietConflictWarnings(ourDefaultParameters.isNoCW(request));
            xslprocessor.setProblemListener(listener);
            if (debug)
            {
              ByteArrayOutputStream baos = new ByteArrayOutputStream();
              XSLTResultTarget outBuffer = new XSLTResultTarget(baos);
              setStylesheetParams(xslprocessor, request);
              xslprocessor.process(xmlSource, xslSource, outBuffer);
              baos.writeTo(response.getOutputStream());
              writeLog(listener.getMessage(), response.SC_OK);
            }
            else
            {
              setStylesheetParams(xslprocessor, request);
              xslprocessor.process(xmlSource, xslSource,
                                   new XSLTResultTarget(response.getWriter()));
            }
          }
          catch (Exception exc)
          {
            ApplyXSLException axe = new ApplyXSLException("Exception occurred during Transformation:"
                                                          + EOL + listener.getMessage() + EOL
                                                          + exc.getMessage(), exc,
                                                                              response.SC_INTERNAL_SERVER_ERROR);
            if (debug) writeLog(axe);
            displayException(response, axe, debug);
          }
          finally
          {
            xslprocessor.reset();
          } // end of try ... catch ... finally
        } // end of blank block
    }
      catch (org.xml.sax.SAXException saxExc)
      {
View Full Code Here

Examples of org.apache.xalan.xslt.XSLTProcessor

           java.net.MalformedURLException,
           org.xml.sax.SAXException
  {
    // Have the XSLTProcessorFactory obtain a interface to a
    // new XSLTProcessor object.
    XSLTProcessor processor = XSLTProcessorFactory.getProcessor();

    // Have the XSLTProcessor processor object transform "foo.xml" to
    // System.out, using the XSLT instructions found in "foo.xsl".
    processor.process(new XSLTInputSource("foo.xml"),
                      new XSLTInputSource("foo.xsl"),
                      new XSLTResultTarget(System.out));
  }
View Full Code Here

Examples of org.apache.xalan.xslt.XSLTProcessor

  // Prepare an output source for the results
  XSLTResultTarget result =
      new XSLTResultTarget(pageContext.getOut());

  // Create an XSLT processor and use it to perform the transformation
  XSLTProcessor processor = null;
  try {
      processor = XSLTProcessorFactory.getProcessor();
      processor.process(data, style, result);
  } catch (SAXException e) {
      throw new JspException(e.toString());
  }
  return (EVAL_PAGE);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.