I am new to ant script. I am looking for how to concatenate all the xml file in a folder into a single xml file in ant script.
In my project n number of xml files will
try this
Concatenate a series of files, update the destination file only if is older that all the source files:
Sample code:
<concat destfile="${docbook.dir}/all-sections.xml"
force="no">
<filelist dir="${docbook.dir}/sections"
files="introduction.xml,overview.xml"/>
<fileset dir="${docbook.dir}"
includes="sections/*.xml"
excludes="introduction.xml,overview.xml"/>
</concat>
avoids root tag:
<concat destfile="${docbook.dir}/all-sections.xml" force="no">
<fileset dir="${docbook.dir}" includes="sections/*.xml"/>
<filterchain>
<linecontainsregexp negate="true">
<regexp pattern="<\?xml version"/>
</linecontainsregexp>
</filterchain>
</concat>
Well, assuming the XSLT 2.0 processor used is Saxon 9 then you can do it along the lines of e.g.
<xsl:param name="folder-uri" select="'file:/root/users/foo/foldername'"/>
<xsl:param name="select-pattern" select="'server*.xml'"/>
<xsl:variable name="docs" select="collection(concat($folder-uri, '?select=', $selectPattern))"/>
<xsl:template name="main" match="/">
<xsl:element name="{name($docs[1]/*)}" namespace="{namespace-uri($docs[1]/*)}">
<xsl:copy-of select="$docs/*/node()"/>
</xsl:element>
</xsl:template>