Subject: Re: [xsl] XSLT - Many Input One Output From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Sat, 30 Jul 2005 11:16:31 -0400 |
i have multiple sources (XML files) and want only one output file (one BIG XML file). The number of the XML input files for the transformation is various in any cycle. The structure is always the same.
Inputfiles: commitlog.xml, commitlog_1.xml, commitlog_2.xml, and so on. (The number of the files are various) (the xml files are splitted automatically from the program which creates this xml files).
This "merge" process should happen with a XSL stylesheet.
Is that possible with XSLT ?
I look at the "document()" funktion, but for that function i need the exact name of the XML file which will included.
Have you any workaround for me ?
<filelist> <file url="commitlog.xml"/> <file url="commitlog_1.xml"/> <file url="commitlog_2.xml"/> ... </filelist>
T:\ftemp>type commitlog.xml <logstuff> <log name="commitlog-a"/> <log name="commitlog-b"/> </logstuff> T:\ftemp>type commitlog_1.xml <logstuff> <log name="commitlog_1-a"/> <log name="commitlog_1-b"/> </logstuff> T:\ftemp>type commitlog_2.xml <logstuff> <log name="commitlog_2-a"/> <log name="commitlog_2-b"/> </logstuff> T:\ftemp>type commitmerge.xsl <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/"> <result> <xsl:call-template name="do-files"/> </result> </xsl:template>
<xsl:template name="do-files"> <xsl:param name="counter" select="0"/> <xsl:variable name="filename"> <xsl:text>commitlog</xsl:text> <xsl:if test="$counter > 0"> <xsl:text/>_<xsl:value-of select="$counter"/> </xsl:if> <xsl:text>.xml</xsl:text> </xsl:variable> <xsl:variable name="mergefileroot" select="document( $filename )"/> <xsl:if test="$mergefileroot"> <!--the merge file exists--> <xsl:copy-of select="$mergefileroot/logstuff/log"/> <xsl:call-template name="do-files">x <xsl:with-param name="counter" select="$counter + 1"/> </xsl:call-template> </xsl:if> </xsl:template>
</xsl:stylesheet> T:\ftemp>xslt commitmerge.xsl commitmerge.xsl commitresult.xml Recoverable error Failure reading file:/T:/ftemp/commitlog_3.xml: no more input
T:\ftemp>type commitresult.xml <?xml version="1.0" encoding="utf-8"?> <result> <log name="commitlog-a"/> <log name="commitlog-b"/> <log name="commitlog_1-a"/> <log name="commitlog_1-b"/> <log name="commitlog_2-a"/> <log name="commitlog_2-b"/> </result> T:\ftemp>
-- World-wide on-site corporate, govt. & user group XML/XSL training. G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] XSLT - Many Input One Out, Michael Kay | Thread | Re: [xsl] XSLT - Many Input One Out, KrustyDerClown |
RE: [xsl] XSLT - Many Input One Out, Michael Kay | Date | Re: [xsl] font color, jeb501 |
Month |