Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_jsp thread: Transforming Multiple XMLs


Message #1 by "Hank Hurst" <hhurst@k...> on Wed, 18 Sep 2002 14:40:48
Dude,

clear your mind of questions...

Here is how I'd handle this:

in the jsp file, you need to add an XML tag to surround the multiple blocks
of XML, before giving it to the transformer.

So basically the jsp always adds a <Page>  </Page>  element surrounding
everything.

Then in your xsl you can access the various xml data <xsl:value-of
select="/Page/Home/Whatever/GameTonight7:00Callme" />  <xsl:value-of
select="/Page/Style/Hydralisk" />  

So you would end up doing something like:
String xmlString = "<Page>" + xmlstring1 + xmlstring2 + "</Page>";


When you want to get more advanced you could create a java object with a
couple methods to do that for you, since you dont want too much logic in the
jsp.  (im trying to save you some trouble)

--------
On a more advanced note, I also use objects to represent our xml
elements. There is a java library called jdom.jar  which provides the java
objects we use, its open source code. Building a big xml string also works,
which is what I assume you are doing.

good luck,

BK

-----Original Message-----
From: Hank Hurst [mailto:hhurst@k...]
Sent: Wednesday, September 18, 2002 10:41 AM
To: Pro_JavaServer_Pages
Subject: [pro_jsp] Transforming Multiple XMLs


I am currently using the following code to combine my xslt and xml
documents:

<%@ page contentType="text/html"%>
<%@ page import="javax.xml.parsers.*, org.w3c.dom.*, javax.xml.transform.*,
javax.xml.transform.stream.*, java.io.*"%>

<%
StreamSource xml = new StreamSource(new
File("/WWW/wwwtest/ktest/xml/home.xml"));
StreamSource xsl = new StreamSource(new
File("/WWW/wwwtest/ktest/hank/style/home.xsl"));
StreamResult result = new StreamResult(out);

TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(xsl);

transformer.transform(xml,result);
%>

This method works great until I need to run more then one xml document in
the transformer.  I have tried different methods but I have not found the
right one; nor am I able to find any code examples on the web.  Can anyone
help me here, I need to be able to implement multiple xml documents against
my xslt document.  Please help, send code.
sface

  Return to Index