aspose file tools*
The moose likes XML and Related Technologies and the fly likes View several XSL documents in one HTML page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "View several XSL documents in one HTML page" Watch "View several XSL documents in one HTML page" New topic
Author

View several XSL documents in one HTML page

Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
Hello.

Suppose you want to print out several documents (Invoices) at once from a browser (HTML page). The invoice is generated in a servlet, where a XML document is translated into HTML using XSL transformation.

What I want is to call XMLOutputter in a servlet to print out several XML/XSL documents in a loop...

At this moment I have a JSP page calling a servlet. The servlet gets a XML document as Blob and translate in into HTML using a XSL file. This work fine, when I print one XML/XSL file only. Please see the code below:

JSP (PrintInvoice.jsp) code looks like this:


Servlet code (InvoiceResponse.java) looks like this:


What I want is to print out several XML/XSL and show it all in HTML.

When running a loop in my JSP code I get the error as follow:
Only one top level element is allowed in an XML document...

Please see the loop below:
JSP (PrintInvoice.jsp) code with loop looks like this:


Any idea how to loop and print several XML/XSL in HTML?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

The error message is pretty clear, isn't it? You can only output one XML document. So continuing with the idea that you can output several XML documents is pointless. Don't waste your time fighting against the rules.

So, now your question is "How can I make several XML documents concatenated together look like a single XML document?" One solution would be to wrap the whole mess in a root element.
Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
Paul Clapham wrote:The error message is pretty clear, isn't it? You can only output one XML document. So continuing with the idea that you can output several XML documents is pointless. Don't waste your time fighting against the rules.

So, now your question is "How can I make several XML documents concatenated together look like a single XML document?" One solution would be to wrap the whole mess in a root element.


To wrap the whole mess in a root element gonna be pretty difficult right?! That´s how it works today:

Today:
1) For each loop we get a blob (XML file) from the database. Each file has it´s own root element.
2) Then we transform the XML file with a XSL file.
3) Then we output the the file.

The new solution:
1) For each loop we get a blob (XML file) from the database. Each file has it´s own root element that we will have to REMOVE.
2) For each loop we store the XML data in a StringBuffer.
3) Finnally we add ONE root element to the StringBuffer.
4) We change the current XSL to be able to transform the concatenated XML in the StringBuffer.
5) Then we output the the StringBuffer.

Is that the way? Is there any other ways? I guess we will have to output everything to a pdf file?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

It doesn't have to be complicated. New solution:

(1) Output start tag of root element
(2) Output all of the documents
(3) Output end tag of root element

PDF!!!??? Where did that come from?
 
Consider Paul's rocket mass heater.
 
subject: View several XSL documents in one HTML page