[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XT as servlet

Subject: Re: XT as servlet
From: Mark Feblowitz <mfeblowitz@xxxxxxx>
Date: Thu, 17 Feb 2000 16:43:48 -0500
servlet download file example
Boy, do I wish this thread had come up before I spent several hours trying to do this. I was able to get the XT servlet running  using  Sun's reference implementation JSP server, jswdk-1.0.1, 
http://java.sun.com/products/servlet/download.htmlhttp://java.sun.com/products/servlet/download.html
I understand that jswdk has been transferred to Apache and is available in version 1.1
        
http://jakarta.apache.org/downloads/binindex.htmlhttp://jakarta.apache.org/downloads/binindex.html)

Like I said, I have gotten the XT Servlet to work, but I'm not completely satisfied with the result. Perhaps someone with experience in deploying Servlets and JSP can fill in my knowledge gaps below.

There is a brief blurb in the XT documentation that tells how to use the included XT servlet,
com.jclark.xsl.sax.XSLServlet
The first thing to grok is the servlet's conceptual model: it is not set up as a general purpose XSL translator, but as a stylesheet-specific translator. When you configure the Servlet, you specify the desired stylesheet in one of the config files. When the servlet initializes, a processor for the specified stylesheet is instantiated. When you visit the URL associated with the servlet, the stylesheet-specific XSLT processor is cloned and the cloned instance sets off to parse and render the XML, according to the pre-specified XSL file. It appears that any processing instruction in the XML file that points to an XSL stylesheet is ignored.

So, in simple terms, you query a reference to an XML file (on the server) and the Servlet processes it according to the one, predefined stylesheet, delivering the result to your browser.

To test this, you could configure a servlet that processes the example file "sort-uniq.xsl" and then browse to the XML file "sort-uniq.xml" - what appears in your browser will be a sorted list of uniquely-occurring bullet items.  BTW, don't try the "slides" example, since the servlet doesn't know what to do with separate files. (I suppose for it, you could write a servlet that processed the XML into a directory and then redirected your browser to the first slide HTML file in the sequence of slides.) If you want to render sort-uniq.xml according to another stylesheet, you'll have to set up another servlet.

I suppose that the source code could be rewritten to pull off a reference to the XSL file, e.g., from a query parameter, and then dynamically instantiate a processor for that spreadsheet. If performance or startup overhead is a factor, then I suppose one could even set up a caching facility to cache multiple stylesheet processors and clone as needed.

Documentation for JSWDK is also light. It tells you to set up an application directory, possibly by cloning the examples directory, and put that into the JSWDK directory.  I called mine XTServlet, but I probably should have called it <stylesheet-name>, e.g., TableRenderer.
jswdk/TableRenderer

In addition, you must declare your application in the webserver.xml file at the JSWDK server's root directory:
<WebApplication id="TableRenderer" mapping="/TableRenderer" docBase="TableRenderer"/>
You then edit the files
TableRenderer/WEBINF/servlets.properties
and
TableRenderer/WEBINF/mappings.properties
putting your code and stylesheet settings in the former:
TableRenderer.code=com.jclark.xsl.sax.XSLServlet
TableRenderer.initparams=stylesheet=/servlets/TableRenderer.xsl
and your mappings in the latter:
        /TableRenderer=TableRenderer
and possibly, also in the latter:
.xml=TableRenderer
These define path mappings for the JSWDK server. This I didn't fully understand. It turns out that if you put in the latter .xml mapping, the mapping portion of Sun's servlet server wipes out critical information from the servlet's init parameters and the servlet can no longer find the stylesheet file.

Next, you compile the XSLServle.java code (don't forget to tell java where the requisite .jar files are) and, using the -d flag and a file path, place the result into in the directory
TableRenderer/WEBINF/servlets
The ultimate contents, if you've done everything correctly, will be in
TableRenderer/WEB-INF/servlets/com/jclark/xsl/sax/XSLServlet.class
Since I declared my stylesheet to be in /servlets/TableRenderer.xsl, I put theTableRenderer.xsl file in the directory

        TableRenderer/servlets   (not TableRenderer/WEBINF/servlets !)

I also put my .xml files, .css files, and .dtd files in that directory, for simplicity.

Finally, there's the URL. To invoke the servlet on "table1.xml", I used the following URL:
http://localhost:8080//TableRenderer/TableRenderer/servlets/table1TableRenderer/TableRenderer/servletshttp://localhost:8080//TableRenderer/TableRenderer/servlets/table1
or
http://localhost:8080//TableRenderer/TableRenderer/servlets/table1.xml
I arrived at this through trial and error. I suspect that there is a simpler URL, but this is the only one that I could get to work.

Note that either IE5 or Netscape 4.x can display the generated HTML (duh), but the XML+XSLT that XT takes is not necessarily going to be rendered properly in IE5 and vice versa. For example, IE5 wants ".[" whereas XT wants "self[".

If anybody knows how to improve on this, please post a followup.



Mark Feblowitz                  mfeblowitz@xxxxxxx
Senior Principal MTS                    (781) 466-2947  
GTE Laboratories Incorporated   (fax) (781) 466-2618
Waltham, MA 02451
http://tec.gte.com/      http://tec.gte.com/MarkFeblowitz XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.