[xsl] Getting unique nodes filtering by several attributes and mixing files

Subject: [xsl] Getting unique nodes filtering by several attributes and mixing files
From: Iván Montoro Ten <ivanm@xxxxxxxxxxx>
Date: Tue, 25 Nov 2003 03:56:56 +0100
Hi,

First of all please excuse my poor english... :)

I'm trying to combine two XML files, mixing the values I realy need from
both and
keeping the result in a third XML file (later I'll convert it to HTML).

One of the XML files (week_schedule.xml) is the list of programs to be on
air for
two different TV channels. This list contains an "onAir" node for each
advertisment
(commercials) block. It's the only way to know which programs will be on air
next
week, yes :(

Now, I'll want to:
* Get unique nodes from weekSchedule, based on progName, channel _and_
weekDay
  (same program can be on air at different times based on week day or
channel,
  for example we repeat the 'Friends' episode of Sunday morning each
Monday).
  I've successfuly got a unique list of progNames, but 'Friends' on Sunday
  dissapear.

* With that unique list of progName/weekDay/channel, resolve the start/end
times
  (calling document() with a local variable). That output should be in XML,
  althought I've got something out in HTML should be little difference,
isn't it?

I'm quite new to XSLT. I've been using it for some time, but basicaly the
database
was giving me the data in format I like, only a few value-of and maybe a
for-each
and HTML is out. I've been read the comments on the list about uniqueness
and
grouping, but as english is not my natural language I'm realy lost, mostly
on the
key() function that seems to make what I want to do.

Thanks!

Ivan

<!-- timetable.xml -->
<!-- I control this file -->
<?xml version="1.0" encoding="ISO-8859-1"?>
<programs>
  <program progName='Friends' weekDay='Mon' channel='1' start='10:00'
end='10:45'/>
  <program progName='X-Files' weekDay='Sat' channel='2' start='14:00'
end='15:30'/>
  <program progName='Friends' weekDay='Sun' channel='1' start='09:00'
end='09:45'/>
</programs>

<!-- week_schedule.xml -->
<!-- This file comes from an external database I don't control -->
<?xml version="1.0" encoding="ISO-8859-1"?>
<weekSchedule>
  <onAir progName='Friends' channel='1' weekDay='Mon' date='17/11/2003'
adsAt='10:15'/>
  <onAir progName='Friends' channel='1' weekDay='Mon' date='17/11/2003'
adsAt='10:30'/>
  <onAir progName='X-Files' channel='2' weekDay='Sat' date='22/11/2003'
adsAt='14:15'/>
  <onAir progName='X-Files' channel='2' weekDay='Sat' date='22/11/2003'
adsAt='14:30'/>
  <onAir progName='X-Files' channel='2' weekDay='Sat' date='22/11/2003'
adsAt='14:45'/>
  <onAir progName='X-Files' channel='2' weekDay='Sat' date='22/11/2003'
adsAt='15:25'/>
  <onAir progName='Friends' channel='1' weekDay='Sun' date='23/11/2003'
adsAt='09:15'/>
  <onAir progName='Friends' channel='1' weekDay='Sun' date='23/11/2003'
adsAt='09:30'/>
</weekSchedule>

<!-- my_result.xml -->
<?xml version="1.0" encoding="ISO-8859-1"?>
<tv>
  <program progName='Friends' channel='1' weekDay='Mon' start='10:00'
end='10:45'/>
  <program progName='Friends' channel='1' weekDay='Sun' start='09:00'
end='09:45'/>
  <program progName='X-Files' channel='2' weekDay='Sat' start='14:00'
end='15:30'/>
</tv>

<!-- my_would_be_even_better_result.xml -->
<?xml version="1.0" encoding="ISO-8859-1"?>
<tv>
  <program progName='Friends' date='17/11/2003'
	channel='1' weekDay='Mon' start='10:00' end='10:45' ads='10:15,10:30'/>
  <program progName='Friends' date='23/11/2003'
	channel='1' weekDay='Sun' start='09:00' end='09:45' ads='14:15,14:30,...'/>
  <program progName='X-Files' date='22/11/2003'
	channel='2' weekDay='Sat' start='14:00' end='15:30' ads='09:15,09:30'/>
</tv>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread