Subject: Re: [xsl] combining 2 different XML files within the same XSLT From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Wed, 28 Aug 2002 09:44:15 +0100 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] combining 2 different XML, Todd Binder | Thread | Re: [xsl] combining 2 different XML, todd binder |
RE: [xsl] reading content with for-, Jarno . Elovirta | Date | Re: [xsl] Returning the file name o, David Carlisle |
Month |