public class MultiXslt
{
public static void main(String[] args) throws TransformerException,ParserConfigurationException, SAXException, IOException
{
//source xslt
StreamSource stylesource = new StreamSource("C:/Users/santhanamk/Desktop/newxslt/Xslt inputs/Idml0.xsl");
DocumentBuilderFactory docbFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder dBuilder = docbFactory.newDocumentBuilder();
//source XML
Document sourceDoc = dBuilder.parse("C:/Users/santhanamk/Desktop/newxslt/input.xml");
DOMSource source = new DOMSource(sourceDoc);
TransformerFactory transformerFactory = TransformerFactory
.newInstance();
Transformer transformer = transformerFactory
.newTransformer(stylesource);
Document document = dBuilder.newDocument();
DOMResult result = new DOMResult(document);
transformer.transform(source, result);
Node resultDoc = ((Document) result.getNode()).getDocumentElement();
System.out.println(resultDoc.getChildNodes().getLength());
// print the result
StringWriter writer = new StringWriter();
Transformer transformer2 = transformerFactory.newTransformer();
transformer2.transform(new DOMSource(resultDoc), new StreamResult(writer));
String s = writer.toString();
}
}
Actually I have one xml file and multi xsl file (C:/Users/santhanamk/Desktop/newxslt/Xslt inputs/list of xsl). when I give the xml and xsl0 as a input, I need to get the output as a string. So after I got the output,I need to give the same output as a input string for xsl1 to get another output(string). Then I need give the output as a input string for xsl2 to get another output. It should give the final output as xml, when the given source directory (C:/Users/santhanamk/Desktop/newxslt/Xslt inputs/list of xsl) doest have any new xsl file to load the output string!