This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: combining 2 different XML files within the same XSLT
- From: "Todd Binder" <todd_binder at hotmail dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Tue, 27 Aug 2002 23:17:44 -0400
- Subject: Re: [xsl] combining 2 different XML files within the same XSLT
- References: <5.1.0.14.0.20020827143302.021f1620@earthlink.net>
- Reply-to: xsl-list at lists dot mulberrytech dot com
This is very close to what I need. The only problem I am encountering is
that the $mergedset of nodes is not sorting (it is sorting within the
file1.xml set of nodes AND within the file2.xml set of nodes, but it is not
mixing the 2 together to allow me to come out with a true mixed sorted list
of nodes.
I would have thought that the below code you supplied would have sorted ALL
the nodes in $mergedset by date, not have done it separately
<xsl:apply-templates select="//date">
<!-- since your criterion is your date, we'll go straight to them -->
<xsl:sort type="number"/>
<!-- let's sort em while we're at it -->
</xsl:apply-templates>
why is this sort not encompassing both sets of nodes? is there a way to
make it sort both set's of nodes?
Could the problem be because if I do a count($mergedset) I get back 2, which
could be telling me that they 2 files are not truely combined, but rather 2
separate nodes in the $mergedset tree?
or does this have to do with sending the second pass you mention? I am
guessing that I was trying to get it all in one pass thru. Would I need to
output the <app> xml and then send it back thru a separate XSL file, or can
I simply pass the newly created <app> xml into another xsl:template in the
same file?
- Todd
----- Original Message -----
From: "Wendell Piez" <wapiez@mulberrytech.com>
To: <xsl-list@lists.mulberrytech.com>
Sent: Tuesday, August 27, 2002 2:48 PM
Subject: Re: [xsl] combining 2 different XML files within the same XSLT
> Todd,
>
> There are any number of approaches to do what you're describing: I'll just
> describe a simple quick-and-dirty "forced merge".
>
> You name the two files in a separate config or "driver" file:
>
> <files>
> <file>file1.xml</file>
> <file>file2.xml</file>
> </files>
>
> This will be the source file for your transformation, in which you do
> something like:
>
> <xsl:variable name="mergedset" select="document(/files/file)"/>
>
> <xsl:template match="/">
> <!-- matching on the root node of your config file -->
> <apps>
> <xsl:apply-templates select="$mergedset" mode="process"/>
> <!-- this mode just bumps you off the default so you can match the
roots
> of your merging documents separately -->
> <!-- you need to wrap them in your <apps> here since there'll be more
than
> one root and you don't want more than one <apps> -->
> </apps>
> </xsl:template>
>
> <xsl:template match="/" mode="process">
> <!-- this template will now match your merging documents' roots -->
> <xsl:apply-templates select="//date">
> <!-- since your criterion is your date, we'll go straight to them -->
> <xsl:sort type="number"/>
> <!-- let's sort em while we're at it -->
> </xsl:apply-templates>
> </xsl:template>
>
> <xsl:template match="date">
> <xsl:if test="
> ...do your test against your criterion of what to include;
> it could of course be parameterized
> ">
> ...
> this is where the action will happen: you'll probably go up a step
> (for-each select=".."), but there's lots of ways to skin this cat:
> the point is you'll build your <app> here and fill it with whatever
> you've got
> ...
> </xsl:if>
> </xsl:template>
>
> >I am trying to create a NEW list of XML nodes from either file that meet
a
> >certain criteria.
>
> BTW (small point), as an English teacher I can't help but urge you to
> understand that "criteria" is a plural noun in our fine language (the word
> comes from Greek), and what you mean to say is "nodes from either file
that
> meet a certain criterion"... :->
>
> Note also that what I'm outlining is a *separate pass* (a pre-process) to
> create a list of <app> elements, not itself suitable for display. Handle
> that either in a second pass, or combine the logic (this is not prima
facie
> impossible) to create your output format with this merging logic, skipping
> the apps/app stage altogether.
>
> I hope that helps!
>
> Cheers,
> Wendell
>
> At 12:32 PM 8/27/2002, you wrote:
> >I have 2 different XML files that have different node structure, but
similar
> >information (both contain date related information)
> >
> >I am trying to create a NEW list of XML nodes from either file that meet
a
> >certain criteria.
> >
> >EXAMPLE FILE 1
> >
> ><events>
> ><event id='1'>
> > <date>20020812</date>
> > <name>event1</name>
> > <fullname>big time event</fullname>
> ></event>
> ><event id='2'>
> > <date>20020813</date>
> > <name>event2</name>
> > <fullname>mid time event</fullname>
> ></event>
> ><event id='3'>
> > <date>20020815</date>
> > <name>event3</name>
> > <fullname>small time event</fullname>
> ></event>
> ></events>
> >
> >EXAMPLE FILE 2
> ><games>
> ><game id='1'>
> > <date>20020813</date>
> > <name>game1</name>
> > <opponent>team b</opponent>
> > <time>14:00</time>
> ></game>
> ><game id='2'>
> > <date>20020818</date>
> > <name>game2</name>
> > <opponent>team c</opponent>
> > <time>12:00</time>
> ></game>
> ></games>
> >
> >is there a way with a single XSLT file to get all the nodes from each
file
> >that meet a certain criteria and put their information into a new XML
node
> >structure?
> >
> >EXAMPLE COMBINED CREATED NODELIST (criteria: date between 20020814 and
> >20020821)
> >
> ><apps>
> ><app type="event" id="3">
> > <date>20020815</date>
> > <name>event3</name>
> > <fullname>small time event</fullname>
> ></app>
> ><app type="game" id="2">
> > <date>20020818</date>
> > <name>game2</name>
> > <opponent>team c</opponent>
> > <time>12:00</time>
> ></app>
> ></apps>
> >
> >this nodelist could then be sorted and displayed (the display XSLT
routine
> >would handle the different @type nodes [game / event] so that even though
> >there would be different information (ie. fullname, opponent, time) the
> >combined list could be sorted and displayed
> >
> >but I can't figure how to create this COMBINED LIST within the XSLT file
> >
> >- Todd
> >
> > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
>
> ======================================================================
> Wendell Piez mailto:wapiez@mulberrytech.com
> Mulberry Technologies, Inc. http://www.mulberrytech.com
> 17 West Jefferson Street Direct Phone: 301/315-9635
> Suite 207 Phone: 301/315-9631
> Rockville, MD 20850 Fax: 301/315-8285
> ----------------------------------------------------------------------
> Mulberry Technologies: A Consultancy Specializing in SGML and XML
> ======================================================================
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list