aspose file tools*
The moose likes XML and Related Technologies and the fly likes Transforming multiple XML/XHTML/HTML file with XSLT using Java (JAXP) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Transforming multiple XML/XHTML/HTML file with XSLT using Java (JAXP)" Watch "Transforming multiple XML/XHTML/HTML file with XSLT using Java (JAXP)" New topic
Author

Transforming multiple XML/XHTML/HTML file with XSLT using Java (JAXP)

Rahul Divedi
Ranch Hand

Joined: Dec 11, 2011
Posts: 40
I want to take multiple input files (XML/HTML/XHTML) and corresponding XSLT to produce the output file for the corresponding Input file. If there is only one input XML file and one input XSLT file then from the following program I'm able to transform it successfully. E.g In the give program my input (X)HTML file is temp.html, input XSLT is temp.xsl which produces the output as temp_copy.html. What would be the best way if I have two or more input files temp1.html and temp2.html and corresponding XSLT temp1.xsl and temp2.xsl, then how can I generate the output temp1_copy.html and temp2_copy.html by using the corresponding input files? Thanking you!

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18662
    
    8

You have two separate transformations, with separate input and output documents?

Then do the first transformation and then do the second transformation.

Or have I misunderstood something?
Rahul Divedi
Ranch Hand

Joined: Dec 11, 2011
Posts: 40
Paul Clapham wrote:You have two separate transformations, with separate input and output documents?

Then do the first transformation and then do the second transformation.

Or have I misunderstood something?


Thanks for the reply. Well, yes I have actually more than one (currently 3) tranformations with separate input and output. So I'm looking for the most precise way to it by executing single program. I have read that it can be achieved by compiling the style sheet with TransformerFactory.newTemplates() and using that template object repeatedly to transform multiple source documents and also using Templates.newTransformer() but I don't have
deep knowledge about this so unable to achieve this. Please help me out in this. Thanking you!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18662
    
    8

Well, yes, you could do that. But it isn't compulsory. You could just take the code you already have and repeat it three times. Or write a loop. There is a trivial solution to your question and a complicated one. Use the trivial one until you find it's unsatisfactory.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Transforming multiple XML/XHTML/HTML file with XSLT using Java (JAXP)