This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: sorting product descriptions


Tobi, you owe me a beer.

You have a solution at http://redrice.com/xml/sortfunction.zip

It's reasonably well-structured, with separate sort and comparison
templates, so that it could be used for other comparison requirements or
with alternative sort algorithms.

There are two interesting problems that have to be cracked, and I'm not
conviced that I've come with the best solution to either.

The first is that it's difficult to implement my favorite sort algorithm
(split down to pairs, then do ordered mereges all the way back up again)
without any ordered assignable data structures in the language. The best
one I could come up with that didn't need this was to pick the highest
on each pass through the unsorted node-set, emit it, then recurse
through the remainder of the node-set. Obviously you could pick the
highest and lowest on each pass, and reduce the number of passes by
about half, but I'd be interested if there was a substantially better
solution.

The second problem is that XSLT doesn't really have a simple operator
for doing string comparisons, so I ended up cheating and using xsl:sort
inside an otherwise unnecessary xsl:for-each. Again, it may well be
possible to improve on this, perhaps using string functions over
variables containing ordered alphabets.

Francis.

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]