This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: combining 2 different XML files within the same XSLT
Jeni, this works perfectly with one small problem.
when using the document(//file) to fill the $mergedset variable, I am not
allowed to have file paths in front of the files
<files>
<file>games.xml</file>
<file>events.xml</file>
</files>
so the XML files have to be in the same directory as the XSL file, not a
huge deal, but I usually keep all the XML files in a separate directory
(cgi-bin/xml) from the XSL files..
so what I would like is
<files>
<file>cgi-bin/xml/ncaa_games.xml</file>
<file>cgi-bin/xml/holidays.xml</file>
</files>
but IF I do that, this doesn't work
<xsl:variable name="mergedset" select="document(//file)"/>
I have tried to use concat() inside the document(), but it doesn't seem to
work..
Is there a way to reference these files when they do not live in the same
directory?
normally I create variables for any files that are not the root file being
used for the transformation (see below)
<xsl:variable name="entry" select="document('cgi-bin/xml/entry.xml')" />
<xsl:variable name="teams" select="document('cgi-bin/xml/teams.xml')" />
and this works just fine, but I can't seem to achive the same thing using
the <files><file> approach....
What am I missing?
- Todd
----- Original Message -----
From: "Jeni Tennison" <jeni@jenitennison.com>
To: "Todd Binder" <todd_binder@hotmail.com>
Cc: <xsl-list@lists.mulberrytech.com>
Sent: Wednesday, August 28, 2002 4:44 AM
Subject: Re: [xsl] combining 2 different XML files within the same XSLT
> Hi Todd,
>
> > 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?
>
> The path "//date" says "from the root node *of the current document*,
> gather together all the date elements and apply templates to them in
> sorted order". You don't want to just sort the date elements of the
> current document -- you want to sort all of the event and game
> elements from both documents.
>
> The $mergedset variable holds the root nodes of the two documents.
> (When you could how many nodes the $mergedset variable holds, you get
> 2 because there are two files -- two root nodes.) To get all the event
> and game elements from both documents, you can use:
>
> $mergedset/events/event | $mergedset/games/game
>
> You can then apply templates to these nodes, sorted in date order, as
> follows:
>
> <xsl:apply-templates select="$mergedset/events/event |
> $mergedset/games/game">
> <xsl:sort select="date" type="number" />
> </xsl:apply-templates>
>
> and have a template that turns both event and game elements into app
> elements:
>
> <xsl:template match="event | game">
> <app type="{local-name()}">
> <xsl:copy-of select="@*" />
> <xsl:copy-of select="*" />
> </app>
> </xsl:template>
>
> If you want to filter the events/games, I suggest that you do so when
> you created the set of events and games, for example use:
>
> ($mergedset/events/event | $mergedset/games/game)
> [date > 20020814 and 20020821 > date]
>
> to get those events and games dated between 20020814 and 20020821
> exclusive.
>
> Cheers,
>
> Jeni
>
> ---
> Jeni Tennison
> http://www.jenitennison.com/
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list