You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by dl...@locus.apache.org on 2000/03/03 22:59:34 UTC

cvs commit: xml-xalan/samples/PureSAX readme.html PureSAX.java

dleslie     00/03/03 13:59:34

  Modified:    samples/PureSAX PureSAX.java
  Added:       samples/PureSAX readme.html
  Log:
  Editorial updates of new sample.
  
  Revision  Changes    Path
  1.2       +33 -12    xml-xalan/samples/PureSAX/PureSAX.java
  
  Index: PureSAX.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/samples/PureSAX/PureSAX.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PureSAX.java	2000/03/03 14:47:29	1.1
  +++ PureSAX.java	2000/03/03 21:59:33	1.2
  @@ -24,7 +24,7 @@
    *    Alternately, this acknowledgment may appear in the software itself,
    *    if and wherever such third-party acknowledgments normally appear.
    *
  - * 4. The names "XSLT4J" and "Apache Software Foundation" must
  + * 4. The names "Xalan" and "Apache Software Foundation" must
    *    not be used to endorse or promote products derived from this
    *    software without prior written permission. For written
    *    permission, please contact apache@apache.org.
  @@ -66,31 +66,52 @@
   import org.apache.xerces.parsers.SAXParser;
   
   /**
  - * Simple sample code to show how to run the XSL processor
  - * from the API, using pure SAX as input.
  + * Run the XSLT processor with SAX input for both the XML input and the stylesheet.
  + * One SAX DocumentHandler produces the stylesheet tree.
  + * Another SAX DocumentHandler produces the
  + * This sample uses some functionality in the processor object (XSLTEngineImpl)
  + * that is not exposed through the XSLTProcessor interface.
    */
   public class PureSAX
   {
   	public static void main(String[] args)
       throws Exception
   	{
  -    // Have the XSLTProcessorFactory obtain a interface to a
  -    // new XSLTProcessor object.
  +    // Create an XSLT processor, returning an XSLTProcessor interface.
       XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
   
  -    // Create a stylesheet using SAX
  +    // Create a stylesheet using SAX.
  +
  +    // Instantiate a Xerces SAX parser.
       SAXParser saxparser = new SAXParser();
  -    StylesheetRoot stylesheet = ((XSLTEngineImpl)processor).createStylesheetRoot("foo.xsl");
  -    StylesheetHandler stylesheetProcessor
  -      = new StylesheetHandler((XSLTEngineImpl)processor, stylesheet);                         
  -    saxparser.setDocumentHandler(stylesheetProcessor);
  +    // 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
  +
  +    // 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 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");
   	}
   }
  
  
  
  1.1                  xml-xalan/samples/PureSAX/readme.html
  
  Index: readme.html
  ===================================================================
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  
  <html>
  <head>
  	<title>Xalan Samples</title>
  </head>
  <body>
  <h2>Xalan Samples</h2>
  <p>For information about the samples (what they illustrate and how to run them), see <a href="../../docs/samples.html">Samples</a>.</p>
  
  
  </body>
  </html>