Subject: Re: [xsl] sort From: "Jonathan Perret" <jonathan@xxxxxxxxxxxx> Date: Fri, 1 Feb 2002 18:43:35 +0100 |
Well, that is exactly how I had understood it the first time. Unfortunately it seems you did not understand what I was suggesting. Perhaps I should have detailed more, but I had only time to focus on the important issue. The solution I gave would allow the client to input either 'person', 'person/extra' or any other path, up to depth 3, and have the list sorted according to their selection (just as you describe). On the other hand, if there is only a limited number of ways the clients may want to sort on, you can also number them (or identify them any other way) and enumerate them as <xsl:sort> elements : <xsl:apply-templates> <xsl:sort select="person[$sortering=1]" /> <xsl:sort select="person/extra[$sortering=2]" /> <xsl:sort select="person/extra/other[$sortering=3]" /> <xsl:sort select="stuff[$sortering=4]" /> </xsl:apply-templates> This way the elements will be sorted on 'person' when $sortering=1, on 'person/extra' when $sortering=2, etc. Just put the number of the column the user clicked on in $sortering. Of course you can use descriptive strings instead of numbers, but I chose numbers to make more explicit the fact that the value of $sortering is not interpreted as a path. This is less generic than what I first suggested but if it works for you... I hope it is clearer at least. Cheers, --Jonathan ----- Original Message ----- From: "Frederic Leclercq" <frederic@xxxxxxxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Saturday, February 02, 2002 2:27 AM Subject: Re: [xsl] sort > Thanks, but maybe my question was not that clear. > I display a table and the clients can click the headers to sort the > table. (html) > > But not every <td></td> is at the same level in the xml-string.... so > some clients would like to sort (at xml level) > <root><person></person></root> > and other clients may want to sort on > <root><person><extra><extra></person></root> > > Hope you understand me ;-) > > Thx in advance, > Fred. > > Jonathan Perret wrote: > > >If the depth of the sorting-element can be bounded to e.g. 3 : > >First, parse your sort specification (e.g., 'person.superlogin.login') into > >several variables - in this case it would give : > >$sortdepth=3 > >$sortering1='person' > >$sortering2='superlogin' > >$sortering3='login' > >For a simpler sort, e.g. on 'person' it would give : > >$sortdepth=1 > >$sortering1='person' > >$sortering2='' > >$sortering3='' > >This is easy to do with substring-before() and substring-after(), so I'll > >leave it as an exercise :-) > > > >Then you can use the following : > > > > <xsl:apply-templates> > > <xsl:sort select="*[name()=$sortering1 and $sortdepth=1]" > >order="{$direction}"/> > > <xsl:sort select="*[name()=$sortering1 and > >$sortdepth=2]/*[name()=$sortering2]" order="{$direction}"/> > > <xsl:sort select="*[name()=$sortering1 and > >$sortdepth=3]/*[name()=$sortering2]/*[name()=$sortering3]" > >order="{$direction}"/> > > </xsl:apply-templates> > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] sort, Frederic Leclercq | Thread | Re: [xsl] sort, David Carlisle |
Re: [xsl] max of sum, Charly | Date | Re: [xsl] sort, David Carlisle |
Month |