Note that there are some explanatory texts on larger screens.

plurals
  1. POApplying single XSLT on thousand XML Files present in a directory
    primarykey
    data
    text
    <p>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 &amp; generate new structured XML corresponding to them. I tried things using Collection() but did not worked. I am using Altova XMLSpy.</p> <p>XML files Looks something like this: </p> <pre><code>&lt;University xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SchemaVersion="1.0.8"&gt; &lt;UniName&gt;StackOverflow&lt;/UniName&gt; &lt;UniId&gt;123&lt;/UniId&gt; &lt;Courses&gt; &lt;Course&gt; &lt;ID&gt;1001&lt;/ID&gt; &lt;Seats&gt;10&lt;/Seats&gt; &lt;Description&gt;Department: CS , Faculty: XYZ&lt;/Description&gt; &lt;/Course&gt; &lt;Course&gt; &lt;ID&gt;1001&lt;/ID&gt; &lt;Seats&gt;10&lt;/Seats&gt; &lt;Description&gt;To teach how to Write XSLT&lt;/Description&gt; &lt;/Course&gt; &lt;Address&gt;Planet No.# 3 Earth&lt;/Address&gt; &lt;ZipCode&gt;007&lt;/ZipCode&gt; &lt;/Courses&gt; &lt;/University&gt; </code></pre> <p>Its Corresponding XSLT Files is:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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"&gt; &lt;xsl:output method="xml" encoding="UTF-8" indent="yes"/&gt; &lt;xsl:template match="/"&gt; &lt;ConnectUni&gt; &lt;xsl:for-each select="University"&gt; &lt;xsl:variable name="var1_resultof_first" as="node()" select="Courses"/&gt; &lt;Address&gt; &lt;xsl:sequence select="fn:string($var1_resultof_first/Address)"/&gt; &lt;/Address&gt; &lt;Courses&gt; &lt;xsl:for-each select="$var1_resultof_first/Course"&gt; &lt;Course&gt; &lt;Id&gt; &lt;xsl:sequence select="fn:string(ID)"/&gt; &lt;/Id&gt; &lt;Seats&gt; &lt;xsl:sequence select="fn:string(Seats)"/&gt; &lt;/Seats&gt; &lt;xsl:apply-templates select="Description"&gt;&lt;/xsl:apply-templates&gt; &lt;/Course&gt; &lt;/xsl:for-each&gt; &lt;/Courses&gt; &lt;/xsl:for-each&gt; &lt;/ConnectUni&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Description"&gt; &lt;xsl:analyze-string select="." regex="Department:\s*(.+)\s*,\s*Faculty:\s*(.+)"&gt; &lt;xsl:matching-substring&gt; &lt;xsl:element name="Department"&gt;&lt;xsl:value-of select="fn:string(regex-group(1))"/&gt; &lt;/xsl:element&gt; &lt;xsl:element name="Faculty"&gt;&lt;xsl:value-of select="fn:string(regex-group(2))"/&gt; &lt;/xsl:element&gt; &lt;/xsl:matching-substring&gt; &lt;xsl:non-matching-substring&gt; &lt;xsl:element name="Description"&gt;&lt;xsl:value-of select="fn:string(.)"/&gt; &lt;/xsl:element&gt; &lt;/xsl:non-matching-substring&gt; &lt;/xsl:analyze-string&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>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.</p> <p>Thank you in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload