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

RE: Re: merging and regrouping multiple xml files

Subject: RE: Re: merging and regrouping multiple xml files
From: "John Reid" <John.Reid@xxxxxxxxxxxxxxx>
Date: Sun, 7 Sep 2003 10:33:11 +1000
process multiple xml files
Thanx Dimitre, worked first time and gave me a method I can use. I gave
it 8MB of data and it was quick( 20 secs)

Salud

John

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Dimitre
Novatchev
Sent: Saturday, 6 September 2003 8:52 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Re: merging and regrouping multiple xml files


Using a two-pass transformation:

  1. Get the nodes from all the files into one document

  2. Group -- e.g. using the Muenchian method

This transformation implements the above solution:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:ext="http://exslt.org/common"
 exclude-result-prefixes="ext"
 >
  <xsl:output omit-xml-declaration="yes" indent="yes"/>
  <xsl:key name="kAsxCode" match="asx" use="code"/>

  <xsl:template match="/">
    <xsl:variable name="vrtfMerged">
      <xsl:copy-of select="document(/*/doc/@filename)"/>
    </xsl:variable>

    <xsl:variable name="vMerged" select="ext:node-set($vrtfMerged)"/>
    <merged>
      <xsl:for-each select="$vMerged">
        <xsl:for-each
             select="xchange/asx[generate-id()
                                =
                                 generate-id(key('kAsxCode', code)[1])
                                ]">
          <asx id="{normalize-space(code)}">
            <xsl:for-each select="key('kAsxCode', code)">
              <day id="{normalize-space(date)}">
                <xsl:copy-of select="*[not(self::date or self::code)]"/>
              </day>
            </xsl:for-each>
          </asx>
        </xsl:for-each>
      </xsl:for-each>
    </merged>
  </xsl:template>
</xsl:stylesheet>

When applied on this source.xml:

<masterfile>
       <doc filename="file08.xml"/>
       <doc filename="file09.xml"/>
</masterfile>

and using the same contents for file08.xml and file09.xml as defined in
your
message, the wanted result is produced:

<merged>
   <asx id="AAB">
      <day id="030905">
         <op> 88</op>
         <hi> 88</hi>
         <lo> 88</lo>
         <cl> 88</cl>
         <vol> 10</vol>
      </day>
      <day id="030906">
         <op> 88</op>
         <hi> 88</hi>
         <lo> 86</lo>
         <cl> 88</cl>
         <vol> 20</vol>
      </day>
   </asx>
   <asx id="AAC">
      <day id="030905">
         <op> 129</op>
         <hi> 129</hi>
         <lo> 127</lo>
         <cl> 128</cl>
         <vol> 99757</vol>
      </day>
      <day id="030906">
         <op> 129</op>
         <hi> 129</hi>
         <lo> 127</lo>
         <cl> 128</cl>
         <vol> 99888</vol>
      </day>
   </asx>
</merged>


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"John Reid" <John.Reid@xxxxxxxxxxxxxxx> wrote in message
news:000d01c37452$c43b0b50$0100a8c0@xxxxxxxx
> I think this is a problem of grouping. I want to tranform a number of
> xml files into one. At the same time regrouping them. The masterfile
> contains the list of files to be merged and file 08 and file09 give
> representative input data. The last list is the desired outcome. I
have
> looked up this type of problem but..
>
> Salud
>
> John
>
> <masterfile>
>        <doc filename="file08.xml"/>
>        <doc filename="file09.xml"/>
>        <doc filename="file10.xml"/>
>        <doc filename="file11.xml"/>
>        <doc filename="file12.xml"/>
>        <doc filename="file13.xml"/>
>        <doc filename="file14.xml"/>
>        <doc filename="file15.xml"/>
>        <doc filename="file16.xml"/>
>        <doc filename="file17.xml"/>
>        <doc filename="file18.xml"/>
>        <doc filename="file19.xml"/>
>        <doc filename="file20.xml"/>
> </masterfile>
>
> file08
>
> <xchange>
>   <asx>
>     <code>AAB</code>
>     <date>030905</date>
>     <op>88</op>
>     <hi>88</hi>
>     <lo>88</lo>
>     <cl>88</cl>
>     <vol>10</vol>
>   </asx>
>   <asx>
>     <code>AAC</code>
>     <date>030905</date>
>     <op>129</op>
>     <hi>129</hi>
>     <lo>127</lo>
>     <cl>128</cl>
>     <vol>99757</vol>
>   </asx>
> </xchange>
>
> file09
> <xchange>
>   <asx>
>     <code>AAB</code>
>     <date>030906</date>
>     <op>88</op>
>     <hi>88</hi>
>     <lo>86</lo>
>     <cl>88</cl>
>     <vol>20</vol>
>   </asx>
>   <asx>
>     <code>AAC</code>
>     <date>030906</date>
>     <op>129</op>
>     <hi>129</hi>
>     <lo>127</lo>
>     <cl>128</cl>
>     <vol>99888</vol>
>   </asx>
> </xchange>
>
> Merged OutPut
>
> <merged>
> <asx id="AAB">
> <day id="030905">
>     <op>88</op>
>     <hi>88</hi>
>     <lo>88</lo>
>     <cl>88</cl>
>     <vol>10</vol>
> </day>
> <day id="030906">
>     <op>88</op>
>     <hi>88</hi>
>     <lo>86</lo>
>     <cl>88</cl>
>     <vol>20</vol>
> </day>
> </asx>
> <asx id="AAC">
> <day id="030905">
>      <op>129</op>
>     <hi>129</hi>
>     <lo>127</lo>
>     <cl>128</cl>
>     <vol>99757</vol>
> </day>
> <day id="030906">
>      <op>129</op>
>     <hi>129</hi>
>     <lo>127</lo>
>     <cl>128</cl>
>     <vol>99888</vol>
> </day>
> </asx>
> Ken Holman gave the below code for something similar and while I feel
> that I should be able to adapt it, I could not.
>
> <?xml version="1.0" encoding="iso-8859-1"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>                  version="1.0">
>
> <xsl:output indent="yes"/>
>
> <xsl:template match="masterfile">
>    <merged>
>      <xsl:variable name="clients"
> select="document(doc/@filename)/client"/>
>
>      <xsl:for-each select="$clients">
>        <xsl:if test="generate-id(.)=
>                      generate-id($clients[name=current()/name])">
>          <client>
>            <xsl:copy-of select="name"/>
>            <xsl:copy-of
> select="$clients[name=current()/name]/subclient"/>
>          </client>
>        </xsl:if>
>      </xsl:for-each>
>    </merged>
> </xsl:template>
>
> </xsl:stylesheet>
> </merged>
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.