multiple html as output from 1 xsl with java



I want to know how can I generate multiple output (html) from one xml using java and xsl.


For example, having this xml:



<ARTICLE>
<SECT>
<PARA>The First 1st Major Section</PARA>
</SECT>
<SECT>
<PARA>The Second 2nd Major Section</PARA>
</SECT>
</ARTICLE>


For each child element "SECT" from "ARTICLE" I would like to have one ".html" as an output, example of the output:


sect1.html



<html>
<body>
<div>
<h1>The First 1st Major Section</h1>
</div>
</body>
</html>


sect2.html



<html>
<body>
<div>
<h1>The First 2nd Major Section</h1>
</div>
</body>
</html>


I've been working in java to transform the .xml document with the next code:



File stylesheet = new File(argv[0]);
File datafile = new File(argv[1]);

DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(datafile);

// Use a Transformer for output
TransformerFactory tFactory = TransformerFactory.newInstance();
StreamSource stylesource = new StreamSource(stylesheet);
Transformer transformer = tFactory.newTransformer(stylesource);

DOMSource source = new DOMSource(document);

OutputStream result=new FileOutputStream("sections.html");

transformer.transform(source, new StreamResult(result));


The problem is that I have only one output, Could you help me to write the .xslt document please? and tell me how to get more than 1 output?


No comments:

Post a Comment