Transforming 10 XML files into new XML files using Java [closed]

NikoRX

New Member
I have a folder of 10 XML files and I had written a corresponding XSLT (Version 2.0). Now I want to write a java code that will enable me to do follwoing:[*]Read all those XML files from the folder and apply XSLT on them individually to generate
new XML files[*]Mark all the read files somehow so that I may not end up reading same file again.I tried first using SAXon and java but things does not worked out. Thank you in advance.Updating The QuestionHere is code of XML File,XSLT File and Java File for reading a single XML file.\[code\]<University xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SchemaVersion="1.0.8"> <UniName>StackOverflow</UniName> <UniId>123</UniId> <Courses> <Course> <ID>1001</ID> <Seats>10</Seats> <Description>Department: CS , Faculty: XYZ</Description> </Course> <Course> <ID>1001</ID> <Seats>10</Seats> <Description>To teach how to Write XSLT</Description> </Course> <Address>Planet No.# 3 Earth</Address> <ZipCode>007</ZipCode> </Courses></University>\[/code\]Its Corresponding XSLT Files is:\[code\]<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="xs fn"><xsl:output method="xml" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <ConnectUni><xsl:for-each select="University"> <xsl:variable name="var1_resultof_first" as="node()" select="Courses"/> <Address> <xsl:sequence select="fn:string($var1_resultof_first/Address)"/> </Address> <Courses> <xsl:for-each select="$var1_resultof_first/Course"> <Course> <Id> <xsl:sequence select="fn:string(ID)"/> </Id> <Seats> <xsl:sequence select="fn:string(Seats)"/> </Seats> <xsl:apply-templates select="Description"></xsl:apply-templates> </Course> </xsl:for-each> </Courses> </xsl:for-each> </ConnectUni></xsl:template><xsl:template match="Description"> <xsl:analyze-string select="." regex="Department:\s*(.+)\s*,\s*Faculty:\s*(.+)"> <xsl:matching-substring> <xsl:element name="Department"><xsl:value-of select="fn:string(regex-group(1))"/> </xsl:element> <xsl:element name="Faculty"><xsl:value-of select="fn:string(regex-group(2))"/> </xsl:element> </xsl:matching-substring> <xsl:non-matching-substring> <xsl:element name="Description"><xsl:value-of select="fn:string(.)"/> </xsl:element> </xsl:non-matching-substring> </xsl:analyze-string> </xsl:template></xsl:stylesheet>\[/code\]Java File:\[code\]import javax.xml.transform.*;import java.io.*;public class Transformed { /** * @param args */public static void main(String[] args) {try { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer (new javax.xml.transform.stream.StreamSource ("working.xslt")); transformer.transform(new javax.xml.transform.stream.StreamSource ("Old_XML_File.xml"), new javax.xml.transform.stream.StreamResult ( new FileOutputStream("New_XML_File.xml"))); } catch (TransformerException e) { e.getMessage( ); } catch (Exception e) { e.getMessage( ); }} }\[/code\]NOTE: This is the Java code I tried did not worked out.
 
Back
Top