Package org.apache.xalan.xslt

Examples of org.apache.xalan.xslt.XSLTProcessor


    /**
     * Compile a new StylesheetRoot from an input file.
     */
    protected StylesheetRoot compileStylesheetRoot (String source) throws Exception
    {
        XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
       
        XSLTInputSource xslin = new XSLTInputSource("file:///"+source);
        StylesheetRoot root = processor.processStylesheet(xslin);

        return root;
    }
View Full Code Here


    /**
     * Execute an xslt
     */
    public void transform (String xslName, Reader in, Writer out) throws Exception
    {
        XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
        XSLTInputSource xmlin = new XSLTInputSource(in);
        XSLTResultTarget xmlout = new XSLTResultTarget(out);
       
        transform (xslName,processor,xmlin,xmlout);       
    }
View Full Code Here

    /**
     * Execute an xslt
     */
    public void transform (String xslName, org.w3c.dom.Node in, Writer out) throws Exception
    {
        XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
        XSLTInputSource xmlin = new XSLTInputSource(in);
        XSLTResultTarget xmlout = new XSLTResultTarget(out);
       
        transform (xslName,processor,xmlin,xmlout);       
    }
View Full Code Here

* 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

     * 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

{
  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

    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

    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

      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

                     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

TOP

Related Classes of org.apache.xalan.xslt.XSLTProcessor

Copyright © 2018 www.massapicom. 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.