[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XSLT - Many Input One Output
At 2005-07-30 16:24 +0200, KrustyDerClown wrote:
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. Where do you keep the list of names of files? This "merge" process should happen with a XSL stylesheet. Absolutely. I look at the "document()" funktion, but for that function i need the exact name of the XML file which will included. True ... but, then, you have to know the names anyway somewhere ... you have to communicate the list of names to your stylesheet. Have you any workaround for me ? If you don't already have it, then you could create a list like the following, since the program that split the information knows how many files there are: <filelist> <file url="commitlog.xml"/> <file url="commitlog_1.xml"/> <file url="commitlog_2.xml"/> ... </filelist> Alternatively, now that I see your file names are deterministic, you could do something along the lines of the stylesheet below. Note how I programmatically increment the filename number (in a recursive loop) until the stylesheet processor detects a failure opening the file. A processor is not obliged to continue processing, but most do, so I don't think this will be a problem for you. If your processor does abort, then you'll need to use some program to read the available files and create an XML list like <filelist> above and go through all of the files without any errors. I hope this helps. . . . . . . . . Ken 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:variable name="base" select="'commitlog'"/> <xsl:output indent="yes"/> <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>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|