|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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
|
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
|

Cart








