xsl-list
[Top] [All Lists]

merging and regrouping multiple xml files

2003-09-06 01:42:09
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



<Prev in Thread] Current Thread [Next in Thread>