Here's the relevant code:
I used Lotus XSLT for transformation.

String xsl = "Catalog.xsl";   //URI of XSL
    //xml is a string which contains the xml generated at runtime
try{
XSLProcessor processor = new XSLProcessor();
XSLTInputSource xslSource = new XSLTInputSource(xsl);
StringReader x = new StringReader(xml);
XSLTInputSource inputSource = new XSLTInputSource (x);
XSLTResultTarget target = new XSLTResultTarget (response.getWriter());
processor.process(inputSource, xslSource, target);
}
catch(Exception e){e.printStackTrace();}

In case u want to use an XML file:
replace the lines:
StringReader x = new StringReader(xml);
XSLTInputSource inputSource = new XSLTInputSource (x);
with
String xml = "Catalog.xml"
XSLTInputSource inputSource = new XSLTInputSource (xml);


HTH
******************************
Lokesh Aggarwal




                    Danny Rubis
                    <[EMAIL PROTECTED]>            To:     [EMAIL PROTECTED]
                    Sent by: "A mailing          cc:
                    list for discussion          Subject:     WML conversion servlet.
                    about Sun
                    Microsystem's Java
                    Servlet API
                    Technology."
                    <SERVLET-INTEREST@jav
                    a.sun.com>


                    10/07/00 06:46 PM
                    Please respond to "A
                    mailing list for
                    discussion about Sun
                    Microsystem's Java
                    Servlet API
                    Technology."





Hey!

Has anyone written servlet that can apply a stylesheet to a source.
It needs to transform using a XSL and an XML documents.

Given a XSL of:
<?xml version="1.0"?>
                      <xsl:stylesheet
xmlns:xsl="http://www.w3.org/TR/WD-xsl">
                        <xsl:template match="/">
                          <html>
                            <body>
                              Title: <xsl:value-of select="book/title"/>

                              <br/>
                              Author: <xsl:value-of
select="book/author"/>
                              <br/>
                              Format: <xsl:value-of
select="book/format/spine"/>
                              <br/>
                              <xsl:value-of
select="book/format/pages/@number"/> pages
                            </body>
                          </html>
                        </xsl:template>
                      </xsl:stylesheet>
and an XLM of:

<?xml version="1.0"?>
                      <book>
                        <title>Moby Dick</title>
                        <author>Herman Melville</author>
                        <format>
                          <spine>Hardback</spine>
                          <pages number="559"/>
                        </format>
                      </book>
and produce:

<html>
                    <body>
                          Title: Moby Dick
                          <br/>
                          Author: Herman Melville
                          <br/>
                          Format: Hardback
                          <br/>
                          559 pages
                        </body>
                      </html>

Thank you.

Sans adieu,
Danny Rubis

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to