Return-Path: Delivered-To: apmail-jakarta-struts-user-archive@jakarta.apache.org Received: (qmail 42613 invoked by uid 500); 24 Sep 2001 15:51:34 -0000 Mailing-List: contact struts-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk Reply-To: struts-user@jakarta.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list struts-user@jakarta.apache.org Received: (qmail 42600 invoked from network); 24 Sep 2001 15:51:33 -0000 Received: from bcis006.sengen.com (HELO bcis006.ops.sengen.com) (146.145.17.56) by daedalus.apache.org with SMTP; 24 Sep 2001 15:51:33 -0000 Received: by bcis006.corp.sengen.com with Internet Mail Service (5.5.2653.19) id ; Mon, 24 Sep 2001 11:51:17 -0400 Message-ID: <2FCA28240297D41185310002B30286C29D3BDD@bcis006.corp.sengen.com> From: Ravindran Ramaiah To: "'struts-user@jakarta.apache.org'" Subject: RE: Struts - XML - XSL Date: Mon, 24 Sep 2001 11:51:16 -0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Following are the procedures that can used to apply the style sheet -------------------------------------------------------------------- Once we have already parsed the XML document, the getDocument method = from the parser instance (e.g. DOMParser) should return an object of type Document (which is actually a DOM representation of the XML). This will = be the starting point. To apply the XSLT transformation, you perform the following steps: 1. Create a DOMSource object and implicitly cast it to a SAX = InputSource object. The constructor takes in the Document object as a parameter. InputSource source =3D new DOMSource(document); 2. Instantiate a StyleGenerator object and pass the fully-qualified = class names of the XML and XSL parsers you want to use. StyleGenerator stylegen =3D new StyleGenerator(Consts.SOURCEDOC_PARSER, Consts.STYLESHEET_PARSER); Where: SOURCEDOC_PARSER "com.sengen.utils.DOMParserExtension" STYLESHEET_PARSER "org.apache.xerces.parsers.SAXParser" You can plug-in any DOM / SAX compliant parser you like. In this case = we are using two different parsers: a DOM parser for the XML and a SAX parser = for the XSL. The setup does not have to be this way. This is also the = reason why we have to implicitly casting in step one. 3. Lastly, call the StyleGenerator's applyStylesheet method. = Originally, it only deals with filenames but I overloaded it to accomodate InputSource = and streams. The resulting or transformed XML document is either written to = a file or returned as a byte stream. public void applyStylesheet(String sourceFileName, String = styleFileName, String outputFileName) throws Exception public ByteArrayOutputStream applyStylesheet(String sourceFileName, = String styleFileName) throws Exception public void applyStylesheet(InputSource sourceInput, String = styleFileName, String outputFileName) throws Exception public ByteArrayOutputStream applyStylesheet(InputSource sourceInput, = String styleFileName) throws Exception Where: sourceFileName XML filename styleFileName XSL filename ** =09 outputFileName filename of the resulting (transformed) XML sourceInput InputSource object created in step 1 ** any type of stylesheet like XSL-2-HTML, XSL-2-FO, XSL-2-whatever -lines 3 and 4 correspond to steps 1 and 2 above. -In line 7, he used the fourth version of the applyStylesheet method = and converted the byte array to a string. This string is now the HTML transformation of the XML document. =09 1. public String getPresentation() { 2.=09 3. InputSource source =3D new DOMSource(getDocument()); 4. StyleGenerator stylegen =3D new StyleGenerator(KmpPdfgenConsts.SOURCEDOC_PARSER,KmpPdfgenConsts.STYLESHE= ET_P ARSER); 5.=09 6. try { 7. return stylegen.applyStylesheet(source,getStylesheet()).toString(); 8. } catch(Exception e){ 9. // 10. } 11.=09 12. return ""; 13. } Hope this helps. Thanks, Ravi -----Original Message----- From: Ted Husted [mailto:husted@apache.org] Sent: Monday, September 24, 2001 11:33 AM To: struts-user@jakarta.apache.org Subject: Re: Struts - XML - XSL At Jakarta, we use Ant to build our HTML pages from XML and XSL. See = the Struts source distribution for an example.=20 I haven't tried it, but I keep thinking it would be interesting to do the same with JSPs. This would gives you the flexibility of XML,XLS without changing how = you write your applications, or incurring the overhead of the runtime transformations. > Fr=E9d=E9ric Houbie - ABSIS-GROUP wrote: >=20 > Hi, >=20 > I'm involved in a project that use struts. I have a question to get > some advice from you. The application want to separate clearly layout > from the logic. The team manager want us to use XML, XSL to build = html > pages. But I don't see clearly how to mix all that. I have beans that > do SQL query and return an iterator with the data, I suppose my > controller servlet must call the beans and give the jsp access to = this > iterator. My JSP page will dynamically build XML file, but i don't > know how to call the transformation of the XML data with a XSL file = to > build my final html layout. >=20 > Can you help me ? >=20 >=20 > Fr=E9d=E9ric Houbie > Internet Project Manager >=20 > ABSIS-GROUP SA > Centre Socran > Av Pr=E9 Aily, 8 > B-4031 Angleur > Tel : +32 4 367 89 64 > Fax : +32 4 367 89 63 >=20 > **** DISCLAIMER **** >=20 > "This e-mail and any attachments thereto may contain information = which > is confidential and/or protected by intellectual property rights and > are intended for the sole use of the recipient(s) named above. Any = use > of the information contained herein (including, but not limited to, > total or partial reproduction, communication or distribution in any > form) by persons other than the designated recipient(s) is = prohibited. > If you have received this e-mail in error, please notify the sender > either by telephone or by e-mail and delete the material from any > computer. >=20 > Thank you for your cooperation." -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel +1 716 737-3463 -- http://www.husted.com/about/struts/