Here's an ugly problem. Michael Kay helped me with a similar problem a few
years ago, but this one is a bit more
complicated. I have a list of flights which needs to be displayed. Each city
gets a line on a screen. I must display as many cities as possible, selecting
initially in order of scheduled time, and then sort alphabetically by city. If
the flight has a remark, then that takes an extra line following each city. If
a remark exists, it must stay on the same page as the city.
Sample XML:
<root>
<row schedule="2004-02-19T07:00:00" flight="DL 1234">
<city order="1">Los Angeles</city>
<city order="2">San Francisco</city>
<city order="3">Seattle</city>
</row>
<row schedule="2004-02-19T07:15:00" flight="DL 3333">
<city order="1">Lincoln</city>
<city order="2">Phoenix</city>
<remark>Flight delayed due to weather conditions</remark>
</row>
<row schedule="2004-02-19T07:30:00" flight="DL 8888">
<city order="1">Chicago</city>
<city order="2">Newark</city>
<city order="3">London</city>
<city order="4">Frankfurt</city>
<city order="5">Istanbul</city>
</row>
<row schedule="2004-02-19T07:45:00" flight="DL 7777">
<city order="1">Denver</city>
<city order="2">Kansas City</city>
<remark>Flight delayed due to maintenance</remark>
</row>
</root>
So let's say, for example, that we can have 5 lines of data per page and we
have a limit of 3 pages. In a typical
environment, I might have 20 lines per page and up to 12 pages and hundreds of
flights. Also, the remarks could take up more than one line.
Page 1:
Chicago DL 8888 07:30
Frankfurt DL 8888 07:30
Istanbul DL 8888 07:30
London DL 8888 07:30
[Lincoln flight moved to page 2 because remark needs to stay on page with
flight]
Page 2:
Lincoln DL 3333 07:15
Flight delayed due to weather conditions
Los Angeles DL 1234 07:00
Newark DL 8888 07:30
[Phoenix flight moved to page 3 because remark needs to stay on page with
flight]
Page 3:
Phoenix DL 3333 07:15
Flight delayed due to weather conditions
San Francisco DL 1234 07:00
Seattle DL 1234 07:00
The 7:45 flight does not get displayed because we don't have enough room on our
pages.
When I iterate through the data, I can determine how many flights will fit on
an individual page. The problem is that when I am doing my initial time-based
selection, I can predict how many lines a flight will take, but I cannot
predict whether the flight is going to fit on a page, forcing me to use an
extra line (chicken or egg scenario). This means that I would have to take an
educated guess at the number of flights which will fit (initially assume that
I'll use all lines of all pages) and then calculate my pages to determine if
they'll fit. If they don't fit, I would then remove the last flight from the
list and try again. This is very inefficient, since I'd need to create a new
node set for each iteration.
Any ideas how to handle this problem cleanly an efficiently in an XSLT
stylesheet?
thanks,
Keith
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list