vubserresiupe
New Member
I had written an XSLT file to transform an XML file from unstructured form to more structured format. But problem is I am having thousands of XML files present in a directory/sub-directory structure and I want to apply same XSLT on all of them & generate new structured XML corresponding to them. I tried things using Collection() but did not worked. I am using Altova XMLSpy.XML files Looks something like this: \[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"><xslutput 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\]I am looking for solution in Java or C# as I have to transform the newly generated XML files into a RDBMS from where SQL queries can be done.Thank you in advance.