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: Re: Sorting date in xsl


Francis Norton wrote:

> Dimitre Novatchev wrote:
> > 
> > 
> > A third and the most natural approach is to use a generic template for a generic
> > sort operation. You'll just pass to this generic template a template reference
> > implementing the "greater than" relation for your format of dates.
> > 
> I'm not sure if it's an official generic template, but I have a generic
> sort function (in fact two of them, but only one works correctly) at
> http://redrice.com/xml/sortfunction_0_1.zip
> 
> Use sortcall.xslt on sort.xml, selecting the simple sort, to demonstrate
> it.
> 
> The point is that you provide your own type-specific comparison template
> and this gets called from your included sort template. There's a
> standard way of calling the sort templates so that you can parameterise
> the choice of method. It's quite a neat solution really.

Hi Francis,

Yes, sortcall.xslt (actually in combination with simplesort.xslt and mergesort.xslt)
implements a generic sorting algorithm.

There are important differences between this implementation and the one based on
template references:

  - Double indirection: a template with fixed name ("before") is called, which then
    based on a parameter calls one of a set of predefined templates. This is done
    through a potentially long xsl:choose.
    When a template reference is used there is no double indirection -- it is
    selected by the XSLT processor based on a uniquely typed node specified in
    the "select" attribute of an xsl:apply-templates within the generic sort
    template.
    No xsl:choose is used.

  - The template to be used for the first indirection (call) must have a unique 
    name. This is not convenient and may cause potential naming conflicts, 
    especially when templates using the generic sort templates are imported.
    Actually, it will not be possible to use in case when two different 
    stylesheets are imported containing templates that each call the sorting 
    template -- they will both have a "before" template. This means that the one
    with the highest import precedence will always be used.

    When using template references there is no such problem -- the templates that 
    implement the "greater-than" relation are not called by name, they are 
    guaranteed to be matching a uniquely typed node and therefore there's actually 
    never more than one template for the XSLT processor to select when resolving the

    xsl:apply-templates from the generic (sort) template.

Thank you for your interest in the implementation of generic templates.
I will be glad to answer any questions regarding this implementation. I will send to
anyone interested the code of some useful generic templates: generic min(), generic
max(), generic binSearch() and generic sort().

Cheers,
Dimitre Novatchev.



__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/

 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]