Re: xt parse

Subject: Re: xt parse
From: Eric van der Vlist <vdv@xxxxxxxxxxxx>
Date: Wed, 23 Feb 2000 22:47:34 +0100
Hi,

Basically, you need to create a XSLProcessor, load the stylesheet, set
the output method handler and destination and parse the XML file.

You can find examples in Driver.java (or XSLServlet.java).

I think the following statements should work...

Hope this helps

Eric

----------------------------------------
    XSLProcessor xsl = new XSLProcessorImpl();
    xsl.setParser(createParser());
    try {
      xsl.loadStylesheet(
	new InputSource("./public_html/xml/cc.xsl");
      OutputMethodHandlerImpl outputMethodHandler = new
OutputMethodHandlerImpl(xsl);
      xsl.setOutputMethodHandler(outputMethodHandler);
      outputMethodHandler.setDestination(new
FileDescriptorDestination(FileDescriptor.out));
      xsl.parse(fileInputSource("./public_html/xml/cc.xml"));
    }

// assuming you define the following functions :
 
  static Parser createParser() {
    String parserClass =
System.getProperty("com.jclark.xsl.sax.parser");
    if (parserClass == null)
      parserClass = System.getProperty("org.xml.sax.parser");
    if (parserClass == null)
      parserClass = "com.jclark.xml.sax.CommentDriver";
    try {
      return (Parser)Class.forName(parserClass).newInstance();
    }
    catch (ClassNotFoundException e) {
      System.err.println(e.toString());
    }
    catch (InstantiationException e) {
      System.err.println(e.toString());
    }
    catch (IllegalAccessException e) {
      System.err.println(e.toString());
    }
    catch (ClassCastException e) {
      System.err.println(parserClass + " is not a SAX driver");
    }
    return null;
  }

  static public InputSource fileInputSource(String str) {
    return fileInputSource(new File(str));
  }

  static public InputSource fileInputSource(File file) {
    String path = file.getAbsolutePath();
    String fSep = System.getProperty("file.separator");
    if (fSep != null && fSep.length() == 1)
      path = path.replace(fSep.charAt(0), '/');
    if (path.length() > 0 && path.charAt(0) != '/')
      path = '/' + path;
    try {
      return new InputSource(new URL("file", "", path).toString());
    }
    catch (java.net.MalformedURLException e) {
      /* According to the spec this could only happen if the file
	 protocol were not recognized. */
      throw new Error("unexpected MalformedURLException");
    }
  }

Paul Beer wrote:
> 
> could someone point me in the direction of api documentation for jclark's xt
> parser ?  how do i do the equivalent of this :
> 
> XSLTResultTarget outputXML = new XSLTResultTarget(out);
> XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
> processor.process(new XSLTInputSource("./public_html/xml/cc.xml"),new
> XSLTInputSource("./public_html/xml/cc.xsl"),outputXML);
> 
> w/ jclark's xt ?
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

-- 
------------------------------------------------------------------------
Eric van der Vlist                                              Dyomedea

http://www.dyomedea.com                          http://www.ducotede.com
------------------------------------------------------------------------


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread