[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Re: sorting

Subject: RE: Re: sorting
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Tue, 18 Jun 2002 08:50:16 +0100
xslt sort column
> Thanks for the input. 
> However, I wasn't being clear about the line that didn't work:
> 
> <xsl:apply-templates select="row">
>        <xsl:sort select="column[number(@sort-column)]" 
> order="{$sort-order}" /> </xsl:apply-templates>

This means column[position()=number(@sort-column)], i.e. select the
columns whose position is the same as the value of their @sort-column
attribute. I've no idea what you're trying to do, but I'm sure this code
is nonsense.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 
 
> 
> The XML looks as follows:
> 
> <table sort-col="2" sort-order="ascending">
>   <row>
>   <column>A</column>
>   <column>N</column>
>   <column>Z</column>
>  </row>
> </table>
> 
> Since the attribute 'sort-col' is at the <table> level but 
> the select of the <xsl:apply-templates> is at the 
> <row> level, perhaps this is the problem?  The XSLT engine 
> thinks that the attribute is an attribute of 
> row? Is this what you are saying?
> 
> The case where it does work is when the variable is assigned 
> as follows:
> 
> <xsl:template match="table">
>   <xsl:variable name="sort-col" select="number(@sort-col)" /> 
> 
> and then inside the same template:
> 
> <xsl:apply-templates select="row">
>        <xsl:sort select="column[$sort-col]" 
> order="{$sort-order}" /> </xsl:apply-templates> 
> 
> so this guarantees that the 'sort-col' variable is set properly?
> 
> Thanks,
> Stuart Zakon
> Objects by Design
> 
> 
> > Date: Sat, 15 Jun 2002 01:23:05 +0200
> > From: Joerg Heinicke <joerg.heinicke@xxxxxx>
> > Subject: Re:  Re: sorting
> > 
> > OBD wrote:
> > > That works. Thanks.
> > > In case there is no sort column, will setting the 
> variable $chosen 
> > > to some value like 0 disable the sort? This is desired so I don't 
> > > have to use <xsl:if> to special case the
> > > sorting (there is a related thread on this topic but I 
> want to confirm for
> > > this example).
> > 
> > 0 is ok. column[0] doesn't exist, so there is nothing to 
> sort for and
> > you should get the columns unsorted.
> > 
> > > Also, I tried using an attribute directly  in the 
> predicate instead 
> > > of a variable and it didn't work. Is this supposed to 
> work? Example:
> > > 
> > > <xsl:sort select="column[number(@sort-column)]"/>
> > 
> > It's absolutely correct XPATH. But it will not do what you 
> want as you
> > already have seen. Written in this way @sort-column refers to the 
> > column, i.e. the @sort-column's value of the column to sort 
> for. And 
> > column is relative to the expression in the <xsl:for-each 
> select="...">. 
> > I think your only way is to store the @sort-column's value 
> in a variable.
> > 
> > > Is this a valid predicate?  It is still better to use a 
> variable, I 
> > > believe, because then I could use <xsl:if> to set it to 0 
> if there 
> > > was no sort-column attribute and get the
> > > benefits I described above, assuming it works that way.
> > > 
> > > Thanks,
> > > Stuart Zakon
> > 
> > Regards,
> > 
> > Joerg
> > 
> > 
> > 
> > 
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 


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


Current Thread
  • Re: sorting
    • OBD - Fri, 14 Jun 2002 12:27:45 -0400 (EDT)
      • <Possible follow-ups>
      • OBD - Mon, 17 Jun 2002 16:35:38 -0400 (EDT)
        • Joerg Heinicke - Mon, 17 Jun 2002 18:40:55 -0400 (EDT)
        • Michael Kay - Tue, 18 Jun 2002 03:48:40 -0400 (EDT) <=

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.