[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XSLT - Many Input One Output

Subject: Re: XSLT - Many Input One Output
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sat, 30 Jul 2005 11:16:31 -0400
xsl document failure reading file
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.
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).

Where do you keep the list of names of files?


This "merge" process should happen with a XSL stylesheet.

Is that possible with XSLT ?

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>


-- 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.