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

RE: xsl sort: using element attribute as sort key!

Subject: RE: xsl sort: using element attribute as sort key!
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 18 Apr 2005 09:39:45 +0100
xsl attribute as sort key
The value of (df_data/@column = $sort) is a boolean, true or false. So your
sorted sequence will contain all the values for which the content of the
@column attribute is not equal to the value of the variable $sort, followed
by those for which it is equal.

I don't like these XML documents in which the elements are called "row" and
"column". My instinct would be to first transform it to a document that uses
application-oriented tags, for example

<person>
  <name>Value</name>
  <phone>Value2</phone>
</person>

and then use that as the input to your "real" transformation.

But if you need to, the answer to your question is
sort="df_data[@column=$sort]".

And it should be order="{$dir}".

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Adam J Knight [mailto:adam@xxxxxxxxxxxxxxxxx]
> Sent: 18 April 2005 01:29
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  xsl sort: using element attribute as sort key!
>
> Hi all,
>
> I am trying to sort based on an elements attribute. Doesn't
> seem to work.
> Can i do this, and if so, what am i doing wrong?
> Replies greatly appreciated!
>
> $sort parameter = 'name'
> $dir parameter = 'descending'
>
> xml structure:
> <dfile>
>   <df_data_row>
>     <df_data column='name'>Value</df_data>
>   </df_data_row>
>   <df_data_row>
>     <df_data column='phone'>Value2</df_data>
>   </df_data_row>
> </dfile>
>
> <xsl:if test="$sort">
>   <xsl:apply-templates select="dfile/df_data_row">
>     <xsl:sort select="df_data/@column = $sort"
> order="$dir"></xsl:sort>
>   </xsl:apply-templates>
> </xsl:if>
>
> Cheers,
> Adam
>  

Current Thread

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-2013 All Rights Reserved.